Example #1
0
 public static function saveBook($data)
 {
     $book = new Book();
     //TODO: validation for data
     $book->title = $data['title'];
     $book->isbn10 = $data['isbn10'];
     $book->cover_pic = $data['picture'];
     $author = new Author();
     $genre = new Genre();
     $author->name = $data['author'];
     $genre->name = $data['genre'];
     $existingAuthor = Author::find($data['existing-author']);
     $existingGenre = Genre::find($data['existing-genre']);
     $book->save();
     if ($data['author'] != '') {
         $book->authors()->save($author);
     }
     if ($data['genre'] != '') {
         $book->genres()->save($genre);
     }
     $book->authors()->attach($existingAuthor['author_id']);
     $book->genres()->attach($existingGenre['genre_id']);
 }
 /**
  * Synchronisation aller neuen Autoren und Kategorien
  *
  * @param Book $book
  * @param array $Authors
  * @param array $Category
  */
 private function Sync(Book $book, array $Authors, array $Category)
 {
     $book->authors()->sync($Authors);
     $book->categorie()->sync($Category);
 }