How to display the image from the public/storage/images in Laravel

woofMaranon :

profile.blade.php

 <form action="{{route('user.profile.update',$user)}}" method="post" enctype="multipart/form-data">
            @csrf
            @method('PUT')

                <div>
                <img height="100px;" class="img-profile rounded-circle" src="{{$user->avatar}}">

                </div>
                <br>
                <div class="form-group">
                <input type="file" name="avatar">

                </div>
    </form>

web.php

Route::put('admin/users/{user}/update','UserController@update')->name('user.profile.update');

User.php

public function getAvatarAttribute($value){
        return asset($value);
    }

UserController:

public function update(User $user){


        $inputs=request()->validate([

                'file'=>['file'],




                ]);


        if(request('avatar')){
           $inputs['avatar']=request('avatar')->store('images');
        }

        $user->update($inputs);

        return back();
    }
}

This is a profile.blade.php

enter image description here

How to display the image from the public/storage/images in Laravel

enter image description here

If I inspect the image the src is src="http://127.0.0.1:8000/images/dT9gvraL3HbTlHcQly96YwoSJdikNj7fVL1dsIzT.jpeg". How did I do wrong?

Abhishek Honrao :

Considering that you are storing images with name not with url.

Now, in User.php,

public function getAvatarAttribute($value){ 
    return asset('storage/'.$value); 
}

Hope this will help you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to display image in laravel after return image from guzzle API

How i can display image from path Laravel?

how to display image from path stored in database? in laravel

Laravel Nova: how to display image from binary string?

How to display image sent from Laravel in email message

How to display an image from s3 bucket in laravel 9

How display image in laravel 5.3

How to display an image from database to background-image css property in laravel?

display image in react from laravel folder

Laravel display image from path which is in database

Display one image from database in laravel

display image from storage laravel 5.3

Display array format image from database in laravel

How to display image using Laravel 5.8?

How to display image in yajra datatable in laravel

How to display an storage image Laravel 5.2

How to display image from URL from Firestore

How to display image from aws s3 in blade laravel 5.2

How can i store image and display it in webpage from database in laravel 4

How to display an image from a database using ajax

how to download and display an image from an URL in R?

How do I display an image from an attachment?

how to display an image from an array using raylib

How to display image in a row from database?

How to display image returned from Mongoid::GridFs

How to display an image from the Gallery in an ImageView?

How to display an image from a numpy array in tkinter?

How to display Original image from folder codeignihter

How to display the image from ajax success function?

TOP Ranking

HotTag

Archive