예제 #1
0
 public function search(Request $request)
 {
     $key_word = $request->key_word;
     $key_word = explode(" - ", $key_word)[0];
     $books = Book::join('author', 'author.id', '=', 'book.author_id')->join('publisher', 'publisher.id', '=', 'book.publisher_id')->select('book.id', 'title', 'image', 'isbn', 'price', 'sale')->where('book.deleted', '=', 0)->where('quantity', '>', 0)->where(function ($query) use($key_word) {
         $query->where('title', 'like', '%' . $key_word . '%')->orWhere('isbn', 'like', $key_word)->orWhere('author.name', 'like', '%' . $key_word . '%')->orWhere('publisher.name', 'like', '%' . $key_word . '%');
     })->get();
     if ($books->count() == 1) {
         return redirect('book/genre/' . $books[0]->id);
     }
     return view('pages.result-search', compact('key_word'))->with('books', $books);
 }
예제 #2
0
 public function show($genre_id, $id)
 {
     $book = Book::join('genre', 'genre.id', '=', 'book.genre_id')->join('author', 'author.id', '=', 'book.author_id')->join('publisher', 'publisher.id', '=', 'book.publisher_id')->select('book.id', 'title', 'genre_id', 'genre.name as genre_name', 'author_id', 'author.name as author_name', 'publisher_id', 'publisher.name as publisher_name', 'image', 'isbn', 'description_short', 'book.description', 'price', 'sale', 'quantity')->findOrFail($id);
     if ($genre_id != 'genre') {
         $genre = Genre::find($genre_id);
         if ($genre->count() > 0) {
             return view('pages.book')->with('book', $book)->with('genre', $genre);
         } else {
             return view('errors.404');
         }
     } else {
         return view('pages.book')->with('book', $book);
     }
 }