Myo Myat Min's avatar

Faker Image error

Hi i m newbie to Laravel and i m building a project which contains image uploading. Here is my factory code.

'''' $factory->define(News::class, function (Faker $faker) { return [ 'title'=>$faker->sentence, 'body'=>$faker->paragraph, 'image'=> $faker->image(storage_path('images'),400,300, null, false), 'category_id'=>rand(1,5), ]; }); ''''

And the error is

InvalidArgumentException

Cannot write to directory "C:\xampp\htdocs\esportsblog\storage\images"

i also tried with public_path but still got this error.Help me with ths plx. btw i m using window.

0 likes
5 replies
sr57's avatar

Hi @marty3

First make your post (more) readable, put your code between 3 `

like this
1 like
sr57's avatar
sr57
Best Answer
Level 39

Second,, use your public directory :

image' => $faker->image('public/storage/images',400,300, null, false)
1 like
Tray2's avatar

I suggest you use a linux server instead of a windows one. It makes it a lot easier to follow 95% of the guides online and you will have an environment that works almost identical with the server you eventually will host your project on.

There are several options on how to do that.

  1. Use homestead https://laravel.com/docs/8.x/homestead
  2. Use Sail https://laravel.com/docs/8.x/sail
  3. Setup your own virtual machine running a lamp stack. https://www.howtoforge.com/tutorial/install-laravel-on-ubuntu-for-apache/
2 likes

Please or to participate in this conversation.