Laravel public storage returns 404 for images
P粉798343415
P粉798343415 2023-12-12 16:05:09
0
1
493

Following the Laravel documentation (I'm using Laravel with docker using sail), I created a symlink for storage php artisan storage:link. I also tried recreating the link using the full path starting from the root directory.

Then I store a file

// ...
$filename = 'signatures/signature_' . auth()->user()->id . '-' . uniqid() . '.' . $image_type;
Storage::disk('public')->put($filename, $image_base64);

After that I can successfully open my file from the console:

open public/storage/signatures/signature_101-62a876ce68884.png

When I try to access the if from my url, I receive a 404:

http://laravel.test/storage/signatures/signature_101-62a876ce68884.png

I noticed by trying to display the image:

<img src="{{ url('/storage/' . $clients->signature->filename) }}">

I finally tried it

rm public/storage
php artisan optimize:clear
php artisan storage:link

did not succeed

P粉798343415
P粉798343415

reply all(1)
P粉799885311

I found the solution. Laravel recommends using sail first, but the documentation doesn't cover this behavior.

The symbolic link must be created in the container!

In the root directory of the project:

  • rm public/storage
  • docker exec -it php artisan storage: link
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template