当前位置: 首页>>代码示例>>PHP>>正文


PHP Book::with方法代码示例

本文整理汇总了PHP中app\Book::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::with方法的具体用法?PHP Book::with怎么用?PHP Book::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Book的用法示例。


在下文中一共展示了Book::with方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: find

 public function find($id)
 {
     // Get book by id
     $book = Book::with('chapters.pages')->find($id);
     // Passing data to response service
     return $this->responseService->returnMessage($book, 'Book was not Found.');
 }
开发者ID:owemus,项目名称:personal_be,代码行数:7,代码来源:BookService.php

示例2: index

 public function index()
 {
     $books = Book::with('Author')->where(function ($query) {
         $min_price = \Request::has('min_price') ? \Request::get('min_price') : null;
         $max_price = \Request::has('max_price') ? \Request::get('max_price') : null;
         $authors = \Request::has('authors') ? \Request::get('authors') : [];
         if (isset($min_price)) {
             $query->where('price', '>=', $min_price);
         }
         if (isset($max_price)) {
             $query->where('price', '<=', $max_price);
         }
         if (isset($authors)) {
             $query->where(function ($q) {
                 $input_authors = \Request::has('authors') ? \Request::get('authors') : [];
                 // $books_all = \App\Book::with('Author')->get();
                 //перебираем все чекнутые боксы
                 foreach ($input_authors as $input_author) {
                     // автор == выборка из авторов где Ид = чекнутому боксу. Первый
                     $author = \App\Author::with('books')->where('id', '=', $input_author)->first();
                     // выборка внутри выбранного автора по книгам
                     foreach ($author->books as $author_book) {
                         //запрос Айди книги == айди книг у этого автора
                         $q->orWhere('id', '=', $author_book->id);
                     }
                 }
             });
         }
     })->paginate(2);
     $authors_list = \App\Author::all();
     return view('books.list', compact('books', 'authors_list'));
 }
开发者ID:aleximillers,项目名称:estore-laravel-angular,代码行数:32,代码来源:BooksController.php

示例3: dump

 function getExample8()
 {
     $book = \App\Book::with('author')->first();
     dump($book->toArray());
     echo $book->title . ' was written by ';
     //echo $book->author->first_name;
     //echo $book->title.' was written by '.$book->author->first_name.' '.$book->author->last_name;
 }
开发者ID:hotlcsw1,项目名称:foobooks,代码行数:8,代码来源:PracticeController.php

示例4: index

 public function index()
 {
     $books = Book::with(array('authors', 'category', 'format'))->orderBy('book_added_at', 'desc')->paginate(config('library.posts_per_page'));
     $imagePath = \Config::get('library.uploads.webpath');
     $imageCoverName = \Config::get('library.uploads.cover_name');
     $deffaultImage = \Config::get('library.uploads.deffault_image');
     return view('allBook', compact('books', 'imagePath', 'imageCoverName', 'deffaultImage'));
 }
开发者ID:EmilAleksandrov,项目名称:book-library-laravel,代码行数:8,代码来源:BookController.php

示例5: foreach

 /**
  * Get all the books with their authors
  */
 function getExample9()
 {
     # Eager load the authors with the books
     $books = \App\Book::with('author')->get();
     foreach ($books as $book) {
         echo $book->author->first_name . ' ' . $book->author->last_name . ' wrote ' . $book->title . '<br>';
     }
     dump($books->toArray());
 }
开发者ID:jpedroza,项目名称:foobooks-master-test.aacax.net,代码行数:12,代码来源:PracticeController.php

示例6: foreach

 function getExample11()
 {
     $books = \App\Book::with('tags')->get();
     foreach ($books as $book) {
         echo '<br>' . $book->title . ' is tagged with: ';
         foreach ($book->tags as $tag) {
             echo $tag->name . ' ';
         }
     }
 }
开发者ID:joshvisk,项目名称:foobooks,代码行数:10,代码来源:PracticeController.php

示例7: getEdit

 /**
  * Responds to requests to GET /books/edit/{$id}
  */
 public function getEdit($id = null)
 {
     // get book to edit
     $book = \App\Book::with('tags')->find($id);
     $authorModel = new \App\Author();
     $authors_for_dropdown = $authorModel->getAuthorsForDropdown();
     // get all the tags
     $tagModel = new \App\Tag();
     $tags_for_checkboxes = $tagModel->getTagsForCheckboxes();
     //dump($tags_for_checkboxes);
     // get the tags for this book
     $tags_for_this_book = [];
     foreach ($book->tags as $tag) {
         $tags_for_this_book[] = $tag->name;
     }
     //dump($tags_for_this_book);
     //dump($authors_for_dropdown);
     if (is_null($book)) {
         \Session::flash('flash_message', 'Book not found.');
         //return redirect('\books');
     }
     return view('books.edit')->with(['book' => $book, 'authors_for_dropdown' => $authors_for_dropdown, 'tags_for_checkboxes' => $tags_for_checkboxes, 'tags_for_this_book' => $tags_for_this_book]);
 }
开发者ID:rhsu0268,项目名称:foobooks,代码行数:26,代码来源:BookController.php

示例8: getEdit

 /**
  * Responds to requests to GET /books/edit/{$id}
  */
 public function getEdit($id = null)
 {
     # Get this book and eager load its tags
     $book = \App\Book::with('tags')->find($id);
     if (is_null($book)) {
         \Session::flash('flash_message', 'Media not found.');
         return redirect('\\books');
     }
     # Get all the possible formats so we can build the formats dropdown in the view
     $formatModel = new \App\Format();
     $formats_for_dropdown = $formatModel->getFormatsForDropdown();
     # Get all the possible tags so we can include them with checkboxes in the view
     $tagModel = new \App\Tag();
     $tags_for_checkbox = $tagModel->getTagsForCheckboxes();
     /*
     Create a simple array of just the tag names for tags associated with this book;
     will be used in the view to decide which tags should be checked off
     */
     $tags_for_this_book = [];
     foreach ($book->tags as $tag) {
         $tags_for_this_book[] = $tag->name;
     }
     return view('books.edit')->with(['book' => $book, 'formats_for_dropdown' => $formats_for_dropdown, 'tags_for_checkbox' => $tags_for_checkbox, 'tags_for_this_book' => $tags_for_this_book]);
 }
开发者ID:jpedroza,项目名称:laravelvideobooks.aacax.net,代码行数:27,代码来源:BookController.php

示例9: books

 public function books()
 {
     $books = Book::with('category', 'shelf')->orderByTitle()->get();
     return view('lms.books', compact('books'));
 }
开发者ID:arooth,项目名称:Library-Management-System,代码行数:5,代码来源:PagesController.php

示例10: showBook

 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function showBook($bookClubId, $bookId)
 {
     //return \App\Book::
     $user = auth()->check() ? auth()->user() : new \App\User();
     $book = \App\Book::with('authors', 'publisher', 'category', 'language')->findOrFail($bookId);
     $statuses = $book->clubStatus($bookClubId);
     $bookclub = \App\BookClub::findOrFail($bookClubId);
     $request_route = 'bookclubs.books.requestbook';
     $book_statuses = \App\BookStatus::all()->lists('name', 'id');
     return view('bookclubs.books.show')->with(compact('book', 'bookclub', 'user', 'statuses', 'request_route', 'book_statuses'));
 }
开发者ID:atindermann08,项目名称:readr,代码行数:17,代码来源:BookClubController.php

示例11: edit

 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $book = \App\Book::with('authors', 'publisher', 'category', 'language')->findOrFail($id);
     $authors = \App\Author::all()->lists('name', 'name');
     $book_authors = $book->authors()->lists('name');
     // return $book_authors;
     return view('books.edit')->with(compact('book'))->with(compact('authors', 'book_authors'));
 }
开发者ID:atindermann08,项目名称:readr,代码行数:14,代码来源:BookController.php

示例12: getBooks

 public function getBooks()
 {
     // API dlya Angular
     return \App\Book::with(["Author"])->with(["categories"])->get();
 }
开发者ID:aleximillers,项目名称:estore-laravel-angular,代码行数:5,代码来源:AdminController.php

示例13: ratingSearch

 public function ratingSearch($rate)
 {
     $books = \App\Book::with('ratings', 'LIKE', $rate)->get();
     foreach ($books as $book) {
         echo '<br>' . $book->title . ' has a rating of';
         $mean = 0;
         $i = 0;
         $rate = 0;
         foreach ($book->rating as $rating) {
             $mean = $mean + $rating;
             $i++;
         }
         $rate = $mean / $i;
         echo ' has a rating of ' + $rate;
     }
 }
开发者ID:snoyface,项目名称:Scifi-book-reviewer,代码行数:16,代码来源:BookController.php


注:本文中的app\Book::with方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。