예제 #1
0
 public function postCreate(Request $request)
 {
     $this->validate($request, ['title' => 'required|min:5', 'author' => 'required|min:5', 'cover' => 'required|url', 'published' => 'required|min:4']);
     //Code here to enter book into the database
     $book = new \Foobooks\Book();
     $book->title = $request->title;
     $book->author = $request->author;
     $book->author_id = $request->author;
     $book->cover = $request->cover;
     $book->published = $request->published;
     $book->purchase_link = $request->purchase_link;
     $book->save();
     //Confirm book was added:
     //send session flash message
     //return view
     \Session::flash('flash_message', 'Your book was added!');
     return redirect('/books');
 }
예제 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // number of database records to create
     $numRows = 100;
     // create Faker object
     $faker = Faker::create();
     for ($i = 0; $i < $numRows; $i++) {
         // create model object
         $book = new \Foobooks\Book();
         $book->title = $faker->sentence($nbWords = 6);
         $book->author = $faker->name;
         $book->published = $faker->year('now');
         $book->cover = $faker->imageUrl(320, 240, 'cats');
         $book->purchase_link = $faker->url;
         $book->page_count = $faker->numberBetween(101, 999);
         $book->save();
         // insert new book in table
     }
 }
예제 #3
0
 function getExample7()
 {
     $author = new \Foobooks\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 \Foobooks\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';
 }