So in the docs is says that you can now easily save files to the storage directory. The example given is for an avatar:
public function update(Request $request)
{
$path = $request->file('avatar')->store('avatars');
return $path;
}
So if you store your avatars to the local storage directory, how do you get them out? Ive been trying to use the Storage facade, but it either returns nothing, freezes up completely, or says it cant find my file. Not quite sure whats going on here. This is my controller logic:
public function update(Request $request)
{
$user = Auth::user();
if ($request->file('userPhoto')) {
$userPhoto = $request->file('userPhoto')->store('photos/user');
// $userPhoto = Storage::putFile('photos/user', $request->file('userPhoto'), 'public');
$profile = UserProfile::firstOrCreate(['user_id' => $user->id()]);
$profile->user_photo = $userPhoto;
$profile->save();
}
return back()->with(['username' => $user->username()]);
}
And heres the code in the view where I try to access it:
<img src="{{ Storage::get($user->profile->userPhoto()) }}">
The path is being stored in the database and the relationship works fine. Only when I try to use Storage to retrieve the photo do run into trouble. I know that generally things in the storage directory are not visible publicaly, but I am under the impression that by using the Storage class, I can allow access to certain items, like an avatar. Am I wrong here?