Take a look at : https://laravel.com/docs/5.5/requests#storing-uploaded-files
$path = $request->avatar->store('avatars', 'public');
Auth::user()->update([
...
'avatar' => $path,
]);
Hello everybody. As I am implementing an Avatar Upload Functionality to my User Profile Setup, I face some problems.
Well, the problem is that when I update my setup with the uploaded avatar, the file name will upload within the DB but doesn't store within my public path.
This is my postEdit Method: $this->validate($request, [
'first_name' => 'alpha|max:50',
'last_name' => 'alpha|max:50',
'location' => 'max:20',
'status' => 'max:50',
'avatar' => 'max:255',
]);
if($request->hasFile('avatar')) {
$file = Input::file ('avatar');
$file = $file -> move(public_path().'/uploads/avatars/', time() .'-'. $file->getClientOriginalName());
}
Auth::user()->update([
'first_name' => $request->input('first_name'),
'last_name' => $request->input('last_name'),
'location' => $request->input('location'),
'status' => $request->input('status'),
'avatar' => $request->input('avatar'),
]);
Any suggestions? Would be very helpful.
Please or to participate in this conversation.