skip to Main Content

I’m trying to generate a fake image to populate seeder data.

I created a seeder with this:

$this->faker->image(storage_path('app/public/products'), 500, 500)

When I try to access them through Laravel Nova to see them, I get this kind of URL: http://localhost/storage/var/www/html/storage/app/public/products/c8831002794cc55fe046c5e2b65794d4.png

In the DB it’s saved as: /var/www/html/storage/app/public/products/c8831002794cc55fe046c5e2b65794d4.png

Any idea what I’ve done wrong?

2

Answers


  1. See the method signature for image():

    function image(
        ?string $dir = null,
        int $width = 640,
        int $height = 480,
        ?string $category = null,
        bool $fullPath = true,
        bool $randomize = true,
        ?string $word = null,
        bool $gray = false,
        string $format = 'png'
    )
    

    Setting $fullPath to false will fix your issue:

    $this->faker->image(storage_path('app/public/products'), 500, 500, null, false)
    
    Login or Signup to reply.
  2. Try this:

    $this->faker->image('app/public/products',400,300, null, false) 
    

    if you have a view then:

    <img src="/my/path/{{ $item->image}}" >
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search