public function search_book()
 {
     $va = $request->input('search_text');
     $b = Book::where('title', 'like', "%" . $va . "%")->count();
     if ($b < 1) {
         Session::flash('flash_message', 'Không tìm thấy kết quả nào!');
         return redirect('/admin_books');
     } else {
         $books = Book::where('title', 'like', "%" . $va . "%")->paginate(6);
         return redirect('books', $books);
     }
 }
Beispiel #2
0
 public function searchResult(Request $request)
 {
     $data_request['search_text'] = $request->input('search_text');
     $data_request['price'] = $request->input('price');
     $data_request['author'] = $request->input('author');
     $data_request['title'] = $request->input('title');
     $data_request['check_author'] = $request->input('check_author');
     $data_request['check_price'] = $request->input('check_price');
     $data_request['check_category'] = $request->input('check_category');
     $data_request['categories'] = $request->input('categories');
     $data['request'] = $data_request;
     $books = Book::where('title', 'like', "%" . $request->input('search_text') . "%");
     if (null !== $request->input('check_author')) {
         $books = $books->where('author', 'like', "%" . $request->input('author') . "%");
         // if($request->input('author')==="1"){
         // 	$books= $books->where('title','like', "%".$request->input('search_text')."%");
         // }else{
         // 	$books= $books->where('author','like', "%".$request->input('search_text')."%");
         // }
     }
     if (null != $request->input('check_category')) {
         $books = $books->join('book_book_cates', 'books.id', '=', 'book_book_cates.book_id')->where('book_book_cates.book_cate_id', '=', (int) $request->input('categories'));
     }
     if (null !== $request->input('check_price')) {
         if ($request->input('price') === "0") {
             $books = $books->where('price', '<', 20);
         } else {
             if ($request->input('price') === "1") {
                 $books = $books->where('price', '>=', 20)->where('price', '<=', 50);
             } else {
                 if ($request->input('price') === "2") {
                     $books = $books->where('price', '>=', 50)->where('price', '<=', 100);
                 } else {
                     if ($request->input('price') === "3") {
                         $books = $books->where('price', '>', 100);
                     }
                 }
             }
         }
     }
     // if(null ===$request->input('check_author')&null ===$request->input('check_price')&null ===$request->input('check_category'))
     // 	$books=Book::where('title', 'like', "%".$request->input('search_text')."%" );
     $check = $books->first();
     if (is_null($check)) {
         return Controller::myView('book.search_result')->with('books', '1');
     }
     $books = $books->paginate(6);
     $data['books'] = $books;
     return Controller::myView('book.search_result')->with($data);
 }
Beispiel #3
0
 public function search($request)
 {
     $books = Book::where('title', 'like', "%" . $request->input('search_text') . "%");
     if (null !== $request->input('check_author')) {
         $books = $books->where('author', 'like', "%" . $request->input('author') . "%");
     }
     if (null != $request->input('check_category')) {
         $books = $books->join('book_book_cates', 'books.id', '=', 'book_book_cates.book_id')->where('book_book_cates.book_cate_id', '=', (int) $request->input('categories'));
     }
     if (null !== $request->input('check_price')) {
         if ($request->input('price') === "0") {
             $books = $books->where('price', '<', 20);
         } else {
             if ($request->input('price') === "1") {
                 $books = $books->where('price', '>=', 20)->where('price', '<=', 50);
             } else {
                 if ($request->input('price') === "2") {
                     $books = $books->where('price', '>=', 50)->where('price', '<=', 100);
                 } else {
                     if ($request->input('price') === "3") {
                         $books = $books->where('price', '>', 100);
                     }
                 }
             }
         }
     }
     if (null !== $request->input('book_status')) {
         if ($request->input('deleted') === "0") {
             $books = $books->where('deleted', '=', 0);
         } else {
             if ($request->input('deleted') === "1") {
                 $books = $books->where('deleted', '=', 1);
             }
         }
     }
     return $books;
 }
Beispiel #4
0
 private function changeUpdate($book, $request)
 {
     $this->book = Book::where('id', '=', (int) $request->input('book_id'))->first();
     $this->book->title = $request->input('title');
     $this->book->author = $request->input('author');
     $this->book->quantity = (int) $request->input('quantity');
     $this->book->price = (int) $request->input('price');
     $this->book->description = preg_replace("/\r\n|\r/", "<br />", $request->input('description'));
     $this->book->deleted = 0;
     $this->book->save();
     $old = array();
     $old[0] = (int) $request->input('old-categories');
     if ($request->input('old-categories1') !== null) {
         $old[1] = (int) $request->input('old-categories1');
     }
     if ($request->input('old-categories2') !== null) {
         $old[2] = (int) $request->input('old-categories2');
     }
     if ($request->input('old-categories3') !== null) {
         $old[3] = (int) $request->input('old-categories3');
     }
     $new = array();
     if ($request->input('categories') !== 0) {
         $new[0] = (int) $request->input('categories');
     } else {
         $new[0] = 0;
     }
     if ($request->input('categories1') !== 0) {
         $new[1] = (int) $request->input('categories1');
     } else {
         $new[1] = 0;
     }
     if ($request->input('categories2') !== 0) {
         $new[2] = (int) $request->input('categories2');
     } else {
         $new[2] = 0;
     }
     if ($request->input('categories3') !== 0) {
         $new[3] = (int) $request->input('categories3');
     } else {
         $new[3] = 0;
     }
     for ($i = 0; $i < count($new); $i++) {
         if ($new[$i] != 0) {
             if (isset($old[$i])) {
                 $book_book_cate = Book_book_cate::where('book_id', '=', $this->book->id)->where('book_cate_id', '=', $old[$i])->first();
             } else {
                 $book_book_cate = new Book_book_cate();
                 $book_book_cate->book_id = $this->book->id;
             }
             $old[$i] = $new[$i];
             $book_book_cate->book_cate_id = $new[$i];
             $book_book_cate->save();
         }
     }
     for ($i = 0; $i < count($old) - 1; $i++) {
         for ($j = $i + 1; $j < count($old); $j++) {
             if (isset($old[$j])) {
                 if ($old[$i] == $old[$j]) {
                     $book_book_cate = Book_book_cate::where('book_id', '=', $this->book->id)->where('book_cate_id', '=', $old[$i])->first();
                     $book_book_cate->delete();
                 }
             }
         }
     }
 }