/** * Upload avatar to Cloudinary and save the returned url to database * * @param Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function updateAvatar(Request $request) { if ($request['file']) { $result = Uploader::upload($request['file'], ["public_id" => Auth::user()->username . rand(1, 100)]); $profile = Profile::where('user_id', Auth::user()->id)->first(); $profile->avatar = $result['url']; $profile->save(); } return redirect('dashboard'); }