successdav's avatar

Display Image from storage directory

Hi! Am so stuck, have tried several method but its not working.

The problem is: I cant display the user image from the storage/app/avaters on my page.

What I want to achieve is: Make it possible for users to upload their profile pictures.

What I have done so far

public function useravater(Request $request)
    {
        $avatar = request()->file('avatar');
        $ext = $avatar->guessClientExtension();
        $file = $avatar->store('avaters');

        $user = User::where('id', Auth()->id())->update([
            'img' => $file, 
        ]);
        return back();
    } 

The image gets upload to Storage/app/avaters verywell and updates the user img user column in the database. I have created also created a sym link: asset('storage/file.txt')

I use this code to display the image on my view

  img src="{{asset('storage/'.Auth::user()->img)}}" alt="" class="user-image"

the image does not show up. This is what i get on the src="" when i check the console

src="http://stechmax.test/storage/avaters/LBP7fucsQoewdXypaARHxlC8jCo1MK47UJFUU3AZ.jpeg" alt="" class="user-image"
0 likes
3 replies
Talinon's avatar

have you run the php artisan storage:link command?

successdav's avatar

yes I have and it returned the [publilc/storage] directory has been linked

1 like

Please or to participate in this conversation.