How to recover image from Storage folder using INTERVENTION IMAGE Laravel 5.2?

Asked

Viewed 551 times

0

This solution works in Public more folder when switching to Storage folder I can’t grab the image and display in the view someone can help me?

Controller

  public function profile(){
    return view('profile', array('user' => Auth::user()) );
}

public function update_avatar(Request $request){

    if($request->hasFile('avatar')){
        $avatar = $request->file('avatar');
        $filename = time() . '.' . $avatar->getClientOriginalExtension();
        Image::make($avatar)->resize(300, 300)->save( storage_path('/uploads/avatars/' . $filename ) );

        $user = Auth::user();
        $user->avatar = $filename;
        $user->save();
    }
    return  view('profile', array('user' => Auth::user()) );
}

Route

Route::get('profile',
'UserController@profile');

Route::post('profile',
'UserController@update_avatar');

View This was the call I made to return the image when it was in the public folder now that it does not work in the Storage folder, does anyone know how I can take the image from the Storage folder and display in the view?

<img src="/uploads/avatars/{{ Auth::user()->avatar }}">

Repository Gitlab https://gitlab.com/ronnyere/Laravel.git

1 answer

0

You will need to create a specific route and controller action to load the images, as the Storage folder is not, or should not be, accessed directly by the browser calls.

For example:

Route

Route::get('/user/picture', 'UserController@getPicture');

Controller

public function getPicture() {
    return \Image::make(file_get_contents('file://'.storage_path('app/fotos/' . Auth::user()->id . 'png')))->response();
}

Vision

<img src="/user/picture">

Note that you need to adapt variable names and file name to your context

Browser other questions tagged

You are not signed in. Login or sign up in order to post.