Using laravel 5.3, I am trying to retrieve an image in a view. How I could do this? folder structure: storage/app/avatard
Here is the code:
public function storeAvatar(Request $request, $username)
{
$user = User::where('name', $username)->first();
$avatar = $request->file('avatar')->store('avatars');
$avatar = explode('avatars/', $avatar);
$user->user_setting()->updateOrCreate(
['user_id' => $user->id],
['avatar' => $avatar[1]]
);
return back();
}
This is how the image path is saved in the database:
/users/avatar/default.png
Somewhat like this you can achieve as storage path is directly unavailable for public. you need to provide public url in route like this.
In view
or
In routes/web.php