示例#1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $photos = ['Happy' => ['happy', 'busy'], 'Easy' => ['easy', 'crazy'], 'Dizzy' => ['dizzy', 'happy']];
     # Now loop through the above array, creating a new pivot for each photo to tag
     foreach ($photos as $title => $tags) {
         # First get the photo matched
         $photo = \P4\Photo::where('title', 'like', $title . '%')->first();
         # Loop through all tags for each photo
         foreach ($tags as $tagName) {
             $tag = \P4\Tag::where('name', 'LIKE', $tagName)->first();
             # Save the photo's tag info
             $photo->tags()->save($tag);
         }
     }
 }
示例#2
0
 protected function makePhoto(UploadedFile $file)
 {
     return Photo::named($file->getClientOriginalName())->move($file);
 }
示例#3
0
 /**
  * Responds to requests to Process /photos/delete/{?id}
  */
 public function getDoDelete($photo_id)
 {
     $photo = \P4\Photo::find($photo_id);
     if (is_null($photo)) {
         \Session::flash('flash_message', 'Photo not found.');
         return redirect('\\photos');
     }
     if ($photo->tags()) {
         $photo->tags()->detach();
     }
     $photo->delete();
     \Session::flash('flash_message', $photo->title . ' was deleted.');
     return redirect('/photos');
 }