Amir
Amir

Reputation: 513

Cannot write to directory using Faker image

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.

Upvotes: 2

Views: 9102

Answers (2)

Braunson
Braunson

Reputation: 717

Looks like the user-group or system cannot write to the folder. php artisan storage:link only creates a symlink to the public folder.

You need to update the permissions on the storage folder to allow creation of files. Check that the user group running the code has permission to write to the storage file and that the storage file has the proper CHMOD permissions

chmod -R 755 storage

Upvotes: 0

user2094178
user2094178

Reputation: 9454

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)

Upvotes: 8

Related Questions