public function show($id)
 {
     $product = Book::findOrFail($id);
     $images = $product->images;
     $authors = $product->Author;
     return view('books.book', compact('product', 'images', 'authors'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Requests\CreateBookRequest $request)
 {
     $Book = \App\Book::findOrFail($id);
     $input = $request->all();
     if (is_null($Book)) {
         return response()->json(['msg' => 'success', 'Book' => 'Book not found'], 404);
     }
     if ($Book->update($input)) {
         return response()->json(['msg' => 'success'], 200);
     } else {
         return response()->json(['msg' => 'error', 'error' => 'cannot update record'], 400);
     }
 }
 /**
  * gives little description of 10 words
  *
  * @param $id
  * @return string
  */
 public function smallDescription($id)
 {
     // $newtext = wordwrap($text, 20, "<br />\n");
     $SmallDescription = str_word_count(Book::findOrFail($id)->description, 1);
     $returnSmallDescription = [];
     foreach ($SmallDescription as $key => $SmallDescriptions) {
         if ($key <= 10) {
             $returnSmallDescription[] = $SmallDescriptions;
         } else {
             break;
         }
     }
     return implode(" ", $returnSmallDescription);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     if (Auth::check()) {
         $selling_price = $request->input("selling_price");
         $book = Book::findOrFail($id);
         $book->selling_price = $selling_price;
         if ($book->save()) {
             return ["code" => 100, "message" => "The selling price of the book is updated in the system"];
         } else {
             return ["code" => 101, "message" => "We cannot update the book prices right now. Please try again after sometime."];
         }
     } else {
         return ["code" => 101, "message" => "You are not authenticated to change price"];
     }
 }
 public function pengembalian($id)
 {
     $returnedAt = time();
     $transaction = Transaction::findOrFail($id);
     $transaction->update(['status' => 1, 'returned_at' => $returnedAt]);
     //ini bisa langsung, cuman kan harus ambil data stock nya dulu mzzz
     //$transaction->book()->update(['stock' => 7]);
     $book = Book::findOrFail($transaction['book_id']);
     $stock = $book['stock'] + 1;
     $book->update(['stock' => $stock]);
     $student = Student::findOrFail($transaction['student_id']);
     $borrow = $student['borrow'] - 1;
     $student->update(['borrow' => $borrow]);
     session()->flash('flash_message', 'You have been doing 1 returned transaction!');
     return redirect()->route('peminjaman.histori');
 }
Exemplo n.º 6
0
 public function removeFromLibrary($bookId)
 {
     //check if book is shared
     $book = \App\Book::findOrFail($bookId);
     if ($book->isShared()) {
         flash()->error('Book is shared with someone. It cannot be removed from library until received back.');
         return \Redirect::back();
     }
     //if not remove from bookclubs
     \DB::table('book_book_club')->where('book_id', $bookId)->where('owner_id', auth()->user()->id)->delete();
     //remove from library
     auth()->user()->books()->detach($bookId);
     flash('Book removed from library and from al book clubs');
     //if yes return with error
     return \Redirect::back();
 }
Exemplo n.º 7
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $book = Book::findOrFail($id);
     return view('layouts.book.show')->with('book', $book);
 }
 public function returnBook($id)
 {
     $book = Book::findOrFail($id);
     $book['rented'] = 0;
     $book['user_id'] = -0;
     $book->update();
     return redirect('Books/rentedBooks');
 }
Exemplo n.º 9
0
 public function update($id, BookRequest $request)
 {
     $book = Book::findOrFail($id);
     $book->update($request->all());
     return redirect('books');
 }
Exemplo n.º 10
0
 /**
  * Extract total hits and Object ids from returned array
  * @param $searchResults
  * @param $type
  * @return array
  */
 private function getObjAndTotal($searchResults, $type)
 {
     if ($type == 'book') {
         $book = array();
         foreach ($searchResults['hits']['hits'] as $hit) {
             try {
                 $book[] = Book::findOrFail($hit['_id']);
             } catch (Exception $exception) {
                 abort(503);
             }
         }
         return ['hits' => $book];
     }
     if ($type == 'user') {
         $user = array();
         foreach ($searchResults['hits']['hits'] as $hit) {
             try {
                 $user[] = User::findOrFail($hit['_id']);
             } catch (Exception $exception) {
                 abort(503);
             }
         }
         return ['hits' => $user];
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $Book = Book::findOrFail($id);
     $Book->delete();
     return redirect('books');
 }
Exemplo n.º 12
0
 public function destroy($id)
 {
     $book = Book::findOrFail($id);
     $book->delete();
 }
Exemplo n.º 13
0
    $book = new \App\Book(['title' => $title, 'pages_count' => $pages_count, 'price' => $price, 'description' => $description, 'author_id' => $author_id, 'publisher_id' => $publisher_id]);
    $book->save();
    // You have to call the save method here if using Method 1 technique
    // Use either of them to insert records into the database
    // For security issues it won't allow you create those records just like that, so...
    // Make sure you have properties $fillable or $guarded in your Model
    // e.g protected $fillable  = ['title','pages_count','price','description','author_id','publisher_id']
    // Method 2 of inserting records into the database via a Model - Mass Assignment
    $book = \App\Book::create(['title' => $title, 'price' => $price, 'pages_count' => $pages_count, 'description' => $description, 'author_id' => $author_id, 'publisher_id' => $publisher_id]);
    echo "Done....";
});
Route::get('book_get_all', function () {
    return \App\Book::all();
});
Route::get('book_get_2', function () {
    return \App\Book::findOrFail(2);
});
Route::get('book_get_3', function () {
    $results = \App\Book::find(3);
    echo $results;
});
Route::get('book_get_where', function () {
    $result = \App\Book::where('pages_count', '<', 1000)->get();
    return $result;
});
Route::get('book_get_where_first', function () {
    $result = \App\Book::where('pages_count', '<', 1000)->first();
    return $result;
});
Route::get('book_get_where_chained', function () {
    $result = \App\Book::where('pages_count', '<', 1000)->where('title', '=', 'My First Book!')->get();
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $BookRating = Book::findOrFail($id);
     $bookRating = $BookRating->getBookRating();
     return $bookRating;
 }
Exemplo n.º 15
0
 public function showBook($id)
 {
     $book = Book::findOrFail($id);
     return View('book', compact('book'));
 }
Exemplo n.º 16
0
 /**
  * Update the specified resource in storage.
  *
  * @param $id
  * @param LibraryRequest $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function update($id, LibraryRequest $request)
 {
     $books = Book::findOrFail($id);
     $bindings = Binding::with('id');
     $categories = Categories::with('id');
     $conditions = Condition::with('id');
     $editions = Edition::with('id');
     $publishers = Publisher::with('id');
     $rarities = Rarity::with('id');
     $signatures = Signature::with('id');
     // Availability option switch (on = 1; off = 0)
     $available = Input::all();
     // Special Collection option switch (on = 1; off = 0)
     $special_collection = Input::all();
     // Handle With Care option switch (on = 1; off = 0)
     $handle_with_care = Input::all();
     $books->update($request->all());
     Auth::user()->books()->save($books, $bindings, $categories, $conditions, $editions, $publishers, $rarities, $signatures, $available, $special_collection, $handle_with_care);
     return redirect('admin/library');
 }
Exemplo n.º 17
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function removeBook($bookClubId, $bookId, Request $request)
 {
     //check if book is shared
     $book = \App\Book::findOrFail($bookId);
     if ($book->isSharedInClub($bookClubId)) {
         flash()->error('Book is shared with someone. It cannot be removed from bookclub until received back.');
         return \Redirect::back();
     }
     $bookclub = \App\BookClub::findOrFail($bookClubId);
     \DB::table('book_book_club')->where('book_club_id', $bookClubId)->where('book_id', $bookId)->where('owner_id', auth()->user()->id)->delete();
     flash('Book removed from club');
     return redirect()->back();
 }
Exemplo n.º 18
0
 public function rating(Request $request, $id)
 {
     $rating = \App\Book::findOrFail($id);
     return Redirect::back();
 }
Exemplo n.º 19
0
 /**
  * Extract total hits and Object ids from returned array
  * @param $searchResults
  * @return array
  */
 private function getObjAndTotal($searchResults)
 {
     $book = array();
     foreach ($searchResults['hits']['hits'] as $hit) {
         try {
             $book[] = Book::findOrFail($hit['_id']);
         } catch (Exception $exception) {
             abort(503);
         }
     }
     return ['hits' => $book];
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $book = Book::findOrFail($id);
     $book->delete();
     return redirect()->route('books.index');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $data = Book::findOrFail($id);
     $data->delete();
     return redirect('BARD_book')->with('status', 'Delete Complete');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $book = Book::findOrFail($id);
     $book->delete();
     //Session::flash('flash_message', 'Task successfully deleted!');
     return redirect()->route('Books.index');
 }