/** * Store filename of user profile in database and file on server in images folder. * @param UpdatePhotoRequest $request file */ public function store_photo(UpdatePhotoRequest $request) { $user = User::find(\Auth::user()->id); $imageName = $user->id . '.' . time() . '.' . $request->file('image')->getClientOriginalExtension(); $request->file('image')->move(public_path() . '/images/profile-image/', $imageName); $user->user_photo_file = $imageName; $user->update(); session()->flash('flash_message', 'Your profile photo has been updated'); return redirect('profile/upload-photo'); }
public function actionUpdate($id, Requests\UpdatePhotoRequest $request) { // Set logged in user to a variable. $authUser = Auth::user(); // Find photo in database. $photo = Photo::where('user_id', '=', $authUser->id)->findOrFail($id); // Update photo in database. $photo->update($request->all()); // Sync tags to photo. $tags = $request->input('tags'); if (!is_array($tags)) { $tags = []; } $tagSync = $this->checkTags($tags); $photo->tags()->sync($tagSync); // Redirect with flash message. \Session::flash('flash_message', 'You have successfully updated a photo.'); return redirect('/photos/' . $photo->id); }