Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot write to directory using Faker image

Tags:

laravel

faker

I want to setup a test data through Faker using a factory. but when I try to add images to the model

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

it returns an error

Cannot write to directory "public/storage/images"

even thought I ran

php artisan storage:link

How to solve this problem? I am using Ubuntu btw.

like image 349
Amir Avatar asked Nov 26 '25 05:11

Amir


1 Answers

You are attempting to write to the directory public/storage/images, this is relative to the root of your server as in /public/storage/images.

You have to write to the storage directory of your app, such as:

$faker->image(storage_path('images'),400,300, null, false)

Or directly to the public folder as well:

$faker->image(public_path('images'),400,300, null, false)
like image 198
user2094178 Avatar answered Nov 28 '25 03:11

user2094178



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!