/** * Responds to requests to POST /landmark/create */ public function postCreate(Request $request) { if (\App\Landmark::where('name', '=', $request->name)->exists()) { \Session::flash('flash_message', 'A Landmark with that name already exists.'); return redirect('\\landmarks'); } $this->validate($request, ['name' => 'required|min:5', 'description' => 'required|min:1', 'location' => 'required|min:1', 'filepath' => 'required|url', 'photo_description' => 'required|min:1']); # Enter landmark and its photo into the database $landmark = new \App\Landmark(); $landmark->name = $request->name; $landmark->description = $request->description; $landmark->location = $request->location; $landmark->user_id = \Auth::id(); # <--- NEW LINE $landmark->save(); $photo = new \App\Photo(); $photo->filepath = $request->filepath; $photo->photo_description = $request->photo_description; $photo->landmark_id = $landmark->id; $photo->user_id = \Auth::id(); $photo->save(); # Add the tags $request->tags; if ($request->tags) { $tags = $request->tags; } else { $tags = []; } $landmark->tags()->sync($tags); # Done \Session::flash('flash_message', 'Your landmark was added!'); return redirect('/landmarks'); }
public function create(Request $request) { $user = new \App\User(); $user->username = $request->username; $user->password = Hash::make($request->password); $user->email = $request->email; $user->firstname = $request->firstname; $user->middlename = $request->middlename; $user->lastname = $request->lastname; $user->permission()->associate(\App\Permission::find($request->permission_id)); $user->save(); $photo = new \App\Photo(); $photo->path = 'default_user_thumbnail.png'; $photo->user()->associate($user); $photo->save(); return $user ? true : false; }
/** * Responds to requests to POST /photos/{id}/create */ public function postCreate(Request $request, $id = null) { $landmark = \App\Landmark::find($id); if (is_null($landmark)) { \Session::flash('flash_message', 'Landmark not found.'); return redirect('\\landmarks'); } if (\App\Photo::where('filepath', '=', $request->filepath)->exists()) { \Session::flash('flash_message', 'A Photo with that URL already exists in our database.'); return redirect('/photos/' . $id); } $this->validate($request, ['filepath' => 'required|url', 'photo_description' => 'required|min:1']); # Enter photo $photo = new \App\Photo(); $photo->landmark()->associate($landmark->id); $photo->user()->associate(\Auth::id()); # <--- NEW LINE $photo->filepath = $request->filepath; $photo->photo_description = $request->photo_description; $photo->save(); # Done \Session::flash('flash_message', 'Your photo was added!'); return redirect('/photos/' . $id); }
public function updateProfile() { $user = \Auth::user(); if ($user == null) { return redirect('home'); } $input = Request::all(); // Validation $v = Validator::make($input, ['first_name' => 'max:50', 'last_name' => 'max:50', 'name' => 'required|max:50|alpha_dash|unique:users,name,' . $user['id'], 'birthday' => 'required|date_format:Y-m-d', 'country' => 'max:50', 'city' => 'max:50', 'occupation' => 'max:50', 'skype_id' => 'min:6|max:32|alpha_num|unique:users,skype_id,' . $user['id'], 'btc_address' => 'min:26|max:35|alpha_num|unique:users,btc_address,' . $user['id'], 'profile_photo' => 'image|max:25000']); if ($v->fails()) { return redirect()->back()->withErrors($v->errors()); } $user->update($input); if (!empty($input['profile_photo'])) { // Save Photos $fileName = time() . '_' . $input['profile_photo']->getClientOriginalName(); $extension = $input['profile_photo']->getClientOriginalExtension(); $user_id = $user['id']; $image = \Image::make(Request::file('profile_photo')); $image->backup(); $imageTypes = array_keys(config('user_image')); foreach ($imageTypes as $imageType) { $path = user_photos_path($imageType); \File::exists($path) or \File::makeDirectory($path, 0775, true); if ($imageType == 'original') { $height = $image->height(); $width = $image->width(); } else { $height = config('user_image' . '.' . $imageType)['height']; $width = config('user_image' . '.' . $imageType)['width']; $image->resize($height, $width); } $image->save($path . $fileName); $image->reset(); // store this path in photos table $photo = new \App\Photo(); $photo['user_id'] = $user_id; $photo['type'] = $imageType; $photo['name'] = $fileName; $photo['height'] = $height; $photo['width'] = $width; $photo['extension'] = $extension; $photo->save(); } } \Session::flash("flash_message", "Your profile has been updated !!!"); return redirect('users'); }