3
votes

in my web application i save users avatar with this method:

$avatarPath = request()->file('avatar')->store('avatars');

then i store $avatarPath in the database. to display the avatar on page i use:

<img class="doc-avatar"  src="{{ Storage::disk('local')->url($doctor->image) }}" />

but as you guess there wont be any image and i don`t know why.

i created a symbolic link with:

php artisan storage:link

also checked the avatars folder in storage/app/public/avatars and my images are in there.

i can get all meta data about image with

Storage::url($doctor->image);

or

Storage::size($doctor->image);

but if i copy the returned URL in the browser there would be 404 error.

http://localhost:8080/storage/avatars/04it83vKYnobT7l8dNXwt1pE0VxiT9L5lQPQ6A1Z.jpeg

http://localhost/storage/avatars/04it83vKYnobT7l8dNXwt1pE0VxiT9L5lQPQ6A1Z.jpeg

both return 404.

and here is my config/filesystem.php

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

'public' => [
    'driver' => 'local',
    'root' => storage_path('app/public'),
    'url' => env('APP_URL').'/storage',
    'visibility' => 'public',
  ],
1
are you uploading them to public folder ? - Mahdi Younesi
not in the public/storage/avatars... all of the are uploading in the storage/app/public/avatars - defectivepixel
Try <img class="doc-avatar" src="{{ asset(Storage::get($doctor->image)) }}" /> - Prince Lionel N'zi
HTTP request has permission to read files inside public folder, You need to give permission to read from other folder - Mahdi Younesi
@MahdiYounesi yeah. thats why i created a symbolic link between public folder and storage folder. i guess? i dont think changing permission of my storage folder is a right move. - defectivepixel

1 Answers

0
votes

the upload will add the images to storage/app/public/avatars, also double check if the files are synced to public/avatars. files under public folder are the only ones accessible not the ones under storage/app/public/avatars.