コード例 #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';
 }
コード例 #2
0
ファイル: BookController.php プロジェクト: sietekk/foobooks
 /**
  * Responds to requests to GET /books/create
  */
 public function getCreate()
 {
     $authorModel = new \App\Author();
     $authors_for_dropdown = $authorModel->getAuthorsForDropdown();
     # Get all the possible tags so we can include them with checkboxes in the view
     $tagModel = new \App\Tag();
     $tags_for_checkbox = $tagModel->getTagsForCheckboxes();
     return view('books.create')->with('authors_for_dropdown', $authors_for_dropdown)->with('tags_for_checkbox', $tags_for_checkbox);
 }
コード例 #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $status = array('active', 'inactive');
     for ($i = 0; $i < 10; $i++) {
         $author = new \App\Author();
         $author->name = 'author-' . $i;
         $author->status = $status[array_rand($status)];
         $author->save();
     }
 }
コード例 #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = \Validator::make(\Input::all(), \App\Author::$rules);
     if ($validator->passes()) {
         $author = new \App\Author();
         $author->name = \Input::get('name');
         $author->bio = \Input::get('bio');
         $author->save();
         flash('Author added.');
         return \Redirect::back();
     }
     return \Redirect::back()->withInput()->withErrors($validator);
 }
コード例 #5
0
 function getExample7()
 {
     $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->author_id = $author->id;
     $book->save();
     dump($book->toArray());
     return 'Added new book.';
 }
コード例 #6
0
ファイル: BookController.php プロジェクト: rhsu0268/foobooks
 /**
  * Responds to requests to GET /books/create
  */
 public function getCreate()
 {
     //return 'Form to create a new book';
     $authorModel = new \App\Author();
     $authors_for_dropdown = $authorModel->getAuthorsForDropdown();
     return view('books.create')->with('authors_for_dropdown', $authors_for_dropdown);
 }
コード例 #7
0
ファイル: layout.blade.php プロジェクト: phucanhhoang/IT4895
<?php

/*layout chung trong project 
 *gom co 
 		header
 			--banner
 			--navigator
 		body
 			--sidebar --content
 		footer	
*/
$books = App\Book::select('title', 'isbn')->get();
$authors = App\Author::select('name')->get();
$publishers = App\Publisher::select('name')->get();
$data = array();
foreach ($books as $book) {
    array_push($data, $book->isbn);
    array_push($data, $book->title . ' - tên sách');
}
foreach ($authors as $author) {
    array_push($data, $author->name . ' - tác giả');
}
foreach ($publishers as $publisher) {
    array_push($data, $publisher->name . ' - nhà xuất bản');
}
echo "<script>var availableTags = " . json_encode($data) . ";</script>";
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
コード例 #8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     $tag_ids = [];
     $users = [];
     $nodes = [];
     static::nodeRecurse($nodes);
     for ($a = 1; $a <= 5; $a++) {
         $tag = new \App\Tag();
         $faker->seed($a + 10);
         $tag->name = $faker->word;
         $tag->save();
         $tag_ids[] = $tag->id;
     }
     $faker->unique(true);
     for ($b = 1; $b <= 20; $b++) {
         $user = new \App\User();
         $faker->seed($a);
         $user->name = $faker->unique()->userName;
         $user->email = $faker->unique()->email;
         $user->password = $faker->password;
         $user->save();
         $users[] = $user;
     }
     foreach ($users as $user) {
         $faker->seed($user->id);
         if ($faker->boolean(40)) {
             // Author
             $author = new \App\Author();
             $author->user()->associate($user);
             $author->name = $faker->name;
             $author->save();
             if ($faker->boolean(50)) {
                 $number_of_likes = $faker->numberBetween(1, count($users));
                 $faker->unique(true);
                 for ($c = 1; $c <= $number_of_likes; $c++) {
                     $like = new \App\Like();
                     $user_key = $faker->unique()->randomElement(array_keys($users));
                     $like->user()->associate($users[$user_key]);
                     $like->likeable()->associate($author);
                     $like->save();
                 }
             }
             if ($faker->boolean(20)) {
                 $number_of_reports = $faker->numberBetween(1, round(count($users) / 3));
                 $faker->unique(true);
                 for ($d = 1; $d <= $number_of_reports; $d++) {
                     $report = new \App\Report();
                     $user_key = $faker->unique()->randomElement(array_keys($users));
                     $report->user()->associate($users[$user_key]);
                     $report->save();
                     $report->authors()->attach($author);
                 }
             }
             if ($faker->boolean(75)) {
                 // At leat 1 article
                 $article_count = $faker->numberBetween(1, 15);
                 for ($e = 1; $e < $article_count; $e++) {
                     $article = new \App\Article();
                     $article->author()->associate($author);
                     $article->title = $faker->sentence($faker->numberBetween(3, 10));
                     $article->body = $faker->paragraphs($faker->numberBetween(2, 8), true);
                     $article->node()->associate($faker->randomElement($nodes));
                     $article->save();
                     $article->tags()->sync($faker->randomElements($tag_ids, $faker->numberBetween(0, min(3, count($tag_ids)))));
                     if ($faker->boolean(10)) {
                         $number_of_reports = $faker->numberBetween(1, round(count($users) / 3));
                         $faker->unique(true);
                         for ($f = 1; $f <= $number_of_reports; $f++) {
                             $report = new \App\Report();
                             $user_key = $faker->unique()->randomElement(array_keys($users));
                             $report->user()->associate($users[$user_key]);
                             $report->save();
                             $report->articles()->attach($article);
                         }
                     }
                     if ($faker->boolean(90)) {
                         $review = new \App\Review();
                         $user_key = $faker->randomElement(array_keys($users));
                         $review->user()->associate($users[$user_key]);
                         $review->reviewable()->associate($article);
                         $review->save();
                     }
                     if ($faker->boolean(69)) {
                         $number_of_likes = $faker->numberBetween(1, count($users));
                         $faker->unique(true);
                         for ($g = 1; $g <= $number_of_likes; $g++) {
                             $like = new \App\Like();
                             $user_key = $faker->unique()->randomElement(array_keys($users));
                             $like->user()->associate($users[$user_key]);
                             $like->likeable()->associate($article);
                             $like->save();
                         }
                     }
                 }
                 if ($faker->boolean(70)) {
                     // At leat 1 comment
                     $comment_count = $faker->numberBetween(1, 20);
                     for ($h = 1; $h < $comment_count; $h++) {
                         $comment = new \App\Comment();
                         $comment->article()->associate($article);
                         $comment->user()->associate($user);
                         $comment->body = $faker->paragraph(4, true);
                         $comment->save();
                         if ($faker->boolean(15)) {
                             $number_of_reports = $faker->numberBetween(1, round(count($users) / 3));
                             $faker->unique(true);
                             for ($i = 1; $i <= $number_of_reports; $i++) {
                                 $report = new \App\Report();
                                 $user_key = $faker->unique()->randomElement(array_keys($users));
                                 $report->user()->associate($users[$user_key]);
                                 $report->save();
                                 $report->comments()->attach($comment);
                             }
                         }
                         if ($faker->boolean(90)) {
                             $review = new \App\Review();
                             $user_key = $faker->randomElement(array_keys($users));
                             $review->user()->associate($users[$user_key]);
                             $review->reviewable()->associate($comment);
                             $review->save();
                         }
                         if ($faker->boolean(60)) {
                             $number_of_likes = $faker->numberBetween(1, count($users));
                             $faker->unique(true);
                             for ($j = 1; $j <= $number_of_likes; $j++) {
                                 $like = new \App\Like();
                                 $user_key = $faker->unique()->randomElement(array_keys($users));
                                 $like->user()->associate($users[$user_key]);
                                 $like->likeable()->associate($comment);
                                 $like->save();
                             }
                         }
                     }
                 }
             }
         }
     }
 }