3 years ago

Populating database with images with Faker

Posted 3 years ago by dust

I want to populate my database with images and in my UserFactory.php I have:

'picture' => $faker->image('public/storage/images',400,300) 

which puts some images in "public/storage/images".

The problem is that It fills that path in my database, and I can't access pictures because my browser wants to see the pictures in "storage/images." If I change path in code to "storage/images" Tinker complains that can't write in that directory "storage/images". So now I have to execute manualy query to fix path.

Is there a smarter way to do that?

  1. How to allow factory to write in "storage/images"?
  2. Is there a way to execute my query automaticaly after Faker finishes. I though about writing unittest so I can execute query imediately after factory but that is not test actualy.
  3. Something else smarter and elegant?

Please sign in or create an account to participate in this conversation.