Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }