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

0

This solution works in the Public Folder more when switching to Storage folder I can not get the image and display in the view Can anyone 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 this in the Storage folder does not work, does anyone know how I can get the image from the storage folder and display it in the view?

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

GitLab Repository link

    
asked by anonymous 13.09.2017 / 16:24

1 answer

0

You will need to create a route and a specific controller action to load the images, as the storage folder is not, or should not, be accessed directly by 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 the filename for your context

    
18.09.2017 / 19:57