Example #1
0
 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.');
 }
 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'));
 }
Example #3
0
 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;
 }
 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'));
 }
 /**
  * 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());
 }
Example #6
0
 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 . ' ';
         }
     }
 }
Example #7
0
 /**
  * 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]);
 }
 /**
  * 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]);
 }
 public function books()
 {
     $books = Book::with('category', 'shelf')->orderByTitle()->get();
     return view('lms.books', compact('books'));
 }
 /**
  * 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'));
 }
Example #11
0
 /**
  * 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'));
 }
 public function getBooks()
 {
     // API dlya Angular
     return \App\Book::with(["Author"])->with(["categories"])->get();
 }
 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;
     }
 }