Tuesday, March 21, 2017

Image retrieving failed with laravel 5.4

I'm trying to store and show image for my app. Image storing properly but failed to show. First I created symbolic link using command: php artisan storage:link
config/filesystem.php look like:

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],
    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],  

to store image:

 if($request->hasFile('avatar'))
{
    $path = $request->file('avatar')->store('avatars'); 
    //$path=avatars/generated_image_name.extension
    $user->avatar=$path;
    $user->save();
}
//image storing under: (../storage/app/avatars)  

to display image to view:

 <img src="storage/"
      alt="no image!!"
      class="img-circle" 
      style="width:150px;height:150px;">

tried src="storage/app/" & src="" but can't fetch image. Don't understand what I'm doing wrong.



via unreleased

Advertisement