Пример #1
0
 function getExample7()
 {
     /*$book = new Book();
       $results = $book->where('published', '>', 1950)->get();
       foreach($results as $result)
       {
           echo $result->title.'<br/>';
       }
       echo 'Number found is '.count($results).'<br/>';
       return 'example7';*/
     $author = new \App\Author();
     $author->first_name = 'J.K';
     $author->last_name = 'Rowling';
     $author->bio_url = 'https://en.wikipedia.org/wiki/J._K._Rowling';
     $author->birth_year = '1965';
     $author->save();
     dump($author->toArray());
     $book = new \App\Book();
     $book->title = "Harry Potter and the Philosopher's Stone";
     $book->published = 1997;
     $book->cover = 'http://prodimage.images-bn.com/pimages/9781582348254_p0_v1_s118x184.jpg';
     $book->purchase_link = 'http://www.barnesandnoble.com/w/harrius-potter-et-philosophi-lapis-j-k-rowling/1102662272?ean=9781582348254';
     $book->author()->associate($author);
     # <--- Associate the author with this book
     $book->save();
     dump($book->toArray());
     return 'Example 7';
 }