public function category($slug) { $Category = Category::findBySlug($slug); $books = Books::where('category_id', '=', $Category->id)->paginate(12); $categories = Category::all(); return view('books.category', compact('books', 'Category', 'categories')); }
protected function curl_run($comicId, $onlineId) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->comic_url . $onlineId . "/"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $matchArr = []; //$output = '<a href="http://8yyls.com/20579">第154話</a>' . '<a href="http://8yyls.com/20375">第004卷</a>'; preg_match_all("/http:\\/\\/8yyls\\.com\\/[0-9]+[\\/]?\">第[0-9]+(卷|話)/", $output, $matchArr, PREG_OFFSET_CAPTURE); $maxNum = last($matchArr[0]); $result = []; $result = explode('">第', $maxNum[0]); $book = \App\Books::where('comics_id', $comicId)->first(); if ($book === null) { $book = new \App\Books(); $book->comics_id = $comicId; $book->link = $result[0]; $book->chapter = substr($result[1], 0, 3); $book->is_read = false; $book->save(); } else { if ($book->chapter !== substr($result[1], 0, 3)) { $book->link = $result[0]; $book->chapter = substr($result[1], 0, 3); $book->is_read = false; $book->save(); } } /** finished curl not test */ curl_close($ch); }
public function getBooks($id) { $categories = \App\categories::all(); $books = \App\Books::where('categoryid', $id)->where('available', 1)->paginate(16); return view('/index', ['categories' => $categories, 'books' => $books]); }
public function postRequest(BookRequest $request) { $bookRequest = new \App\BookRequest(); $bookRequest->userid = session('user')->userid; $bookRequest->bookname = $request->input('bookname'); $bookRequest->categoryid = $request->input('categoryid'); $bookRequest->author = $request->input('author'); $bookRequest->publishedyear = $request->input('publishedyear'); $bookRequest->publishername = $request->input('publishername'); $book = \App\Books::where('bookname', $bookRequest->bookname)->where('author', $bookRequest->author)->where('publishedyear', $bookRequest->publishedyear)->first(); $bookRequest->save(); \Session::flash('message', 'Your book request has been placed successfully!'); \Session::flash('type', 'success'); return redirect('/books/request'); }