Esempio n. 1
0
 /**
  * Store Bookmark in Database
  * @param  array  $modifiers
  * @return App\Models\Bookmark
  */
 public function create($user_id, array $modifiers)
 {
     // $data = array_only($modifiers, ['favourite_id', 'description']);
     if (!isset($modifiers['favourite_id']) || is_null(\App\Models\Favourite::find($modifiers['favourite_id']))) {
         $favourite = new \App\Models\Favourite();
         $favourite->name = $modifiers['name'];
         $favourite->type = $modifiers['type'];
         $favourite->save();
         $movies = new \App\Models\Movie();
         $movies->genre = $modifiers['genre'];
         $movies->country = $modifiers['country'];
         $movies->director = $modifiers['director'];
         $movies->plot = $modifiers['description'];
         $movies->year = $modifiers['year'];
         $movies->favourite_id = $favourite->id;
         $movies->save();
         $favourite_id = $favourite->id;
     } else {
         $favourite_id = $modifiers['favourite_id'];
     }
     $data = array_only($modifiers, ['review']);
     $bookmark = $this->bookmark->create($data);
     $bookmark->favourite_id = $favourite_id;
     $bookmark->user_id = $user_id;
     $bookmark->description = $modifiers['review'];
     $bookmark->save();
     return $bookmark;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('movies')->delete();
     DB::table('favourites')->delete();
     $favourite = new App\Models\Favourite();
     $favourite->name = "The Godfather";
     $favourite->type = "movies";
     $favourite->save();
     $movie = new App\Models\Movie();
     $movie->plot = "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.";
     $favourite->data()->save($movie);
     $favourite->data->save();
     $favourite = new App\Models\Favourite();
     $favourite->name = "The Dark Knight";
     $favourite->type = "movies";
     $favourite->save();
     $movie = new App\Models\Movie();
     $movie->plot = "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.";
     $favourite->data()->save($movie);
     $favourite->data->save();
 }