Because public_path returns your local public path. That might look like this /www/projects/laravel/public/work_photos. Instead, you need to set a relative path
$faker->image('public/work_photos', 400, 300, null, false),
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've created a faker to generate images. I want to store the images to my works folder under public folder. By default faker is storing images to storage. so I changes the image path using public_apth() function. but it didn't storing images. my code is below:
$factory->define(\App\Models\UserPhoto::class, function (Faker $faker) {
return [
'image' => $faker->image(public_path('work_photos'), 400, 300, null, false),
];
});
@bobbybouwmann Thanks for the support. Issue was with the $faker->image() function. $faker->image() function is calling $kaker->imageUrl() function and that function sets $baseUrl variable to lorempixels.com like this$baseUrl = "https://lorempixel.com/";. I replaced https to http and now its working. but I actually don't know why I want ot do this. but its working fine now.
Please or to participate in this conversation.