Skip to content
Advertisement

Laravel image paths from controller to view

My image’s path is public/uploads/users/image.png then using src like this:

<img src="{{ asset('uploads/users/image.png') }}" />

But for every user the image has to be changed.

I pass the image name of the user from controller as something like this

foreach ($user as $key) {
                $this->data['user_img'] = $key->avatar;
            }

Here, I have to change the user image as per $user_img from controller

How should I give it in the src of image tag.

I tried like this way

src="{{ asset('uploads/users/"{{$user_img}}"')}}"

But it seems to be an error for me.How should I resole this.

Somebody help me.

Advertisement

Answer

You can use this method for image in laravel.

if this is your image path public/assets/uploads/users/image.png.

image in $user_img

{{asset('assets/uploads/users').'/'.$user_img}}

Or we can use

{{ asset('assets/uploads/users') }}/{{$user_img}}
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement