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'));
 }
 public function destroy($id)
 {
     $book = Books::find($id);
     ClydeUpload::exists($book->book_cover) == true ? ClydeUpload::delete($book->book_cover) : false;
     $book->delete();
     return redirect()->route('admin.books.index');
 }
 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 update(Request $request)
 {
     $file = Files::find($request->id);
     $file->notes = $request->notes;
     $file->date_store = $request->date_store;
     $file->save();
     return Books::find($request->book_id)->files;
 }
 public function run()
 {
     // CLEAR TABLE BOOKS
     Books::truncate();
     // SEEDS EXECUTE
     $Authors = Authors::all()->each(function ($author) {
         foreach (range(1, 10) as $v) {
             $category = Category::all(['id'])->random(1);
             $author->books()->save(factory('App\\Books')->make(['category_id' => $category->id]));
         }
     });
 }
 protected function readBook($bookId)
 {
     $result = [];
     $result['status'] = false;
     try {
         $book = \App\Books::findOrFail($bookId);
     } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         $result['err_msg'] = "Can't find the book";
         return \Response::json($result);
     }
     $book->is_read = true;
     $book->save();
     $result['status'] = true;
     return \Response::json($result);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request)
 {
     $books = Books::find($request->id);
     if ($request->hasFile('cover')) {
         $filename = substr(md5(time()), 0, 20) . '.' . $request->file('cover')->getClientOriginalExtension();
         $request->file('cover')->move(base_path() . '/public/upload', $filename);
         if (File::exists('public/upload/' . $books->cover)) {
             File::delete('public/upload/' . $books->cover);
         }
         $books->cover = $filename;
     }
     $books->name = $request->name;
     $books->local_number = $request->local_number ?: '';
     $books->international_number = $request->international_number ?: '';
     $books->priority = $request->priority;
     $books->save();
     return response($books, '202');
 }
Example #8
0
 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 static function boot()
 {
     parent::boot();
     Books::observe(new UserActionsObserver());
 }
 /**
  * Return all by book_id
  */
 public function returnAllByBookId($id)
 {
     return Books::find($id)->task;
 }
Example #11
0
 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');
 }
 /**
  * Mass delete function from index page
  * @param Request $request
  *
  * @return mixed
  */
 public function massDelete(Request $request)
 {
     if ($request->get('toDelete') != 'mass') {
         $toDelete = json_decode($request->get('toDelete'));
         Books::destroy($toDelete);
     } else {
         Books::whereNotNull('id')->delete();
     }
     return redirect()->route('admin.books.index');
 }