Search code examples
phplaravellaravel-8laravel-storage

laravel image not found in public/storage


I am trying to access images for my project.

I have run php artisan storage link

Laravel create public/storage

when I upload image to storage/app, I see the image in storage/app but not in public/storage.

When I try to view image on browser, I get error 404

controller.php

Property::create([
'SittingRoom'=> request()->file('sittingroom')->store('apartments')
]);

bladeview.php

<img src="{{asset('storage/'.$duplex->SittingRoom)}}">

browswer link

http://127.0.0.1:8000/storage/apartments/HNLDysVUdRG7ZTBkF2qFGk2B2tAKYzYcVImNEWLx.jpg

after running artisan storage link

C:\xampp\htdocs\OPAAM> php artisan storage:link

INFO The [C:\xampp\htdocs\OPAAM\public\storage] link has been connected to [C:\xampp\htdocs\OPAAM\storage\app/public].


Solution

  • The problem was that in config/filesystems.php

    'default' => env('FILESYSTEM_DISK', 'public'),
    

    but in the .env file

    FILESYSTEM_DISK=local 
    

    This configuration saves your images in Storage/app instead of storage/app/public.

    Images saved in storage/app cannot be accessed publicly. So you have to change the .env file