public function addCart(Request $request) { $book = Book::find($request->id); if ($request->quantity <= $book->quantity) { $cart_old = Cart::where('book_id', '=', $request->id)->where(function ($query) use($request) { $query->where('user_id', '=', Auth::check() ? Auth::user()->id : 0)->orWhere('remember_token', '=', $request->header('X-CSRF-TOKEN')); }); if ($cart_old->count() > 0) { $check = $cart_old->firstOrFail()->update(['quantity' => $cart_old->firstOrFail()->quantity + $request->quantity]); } else { $cart = new Cart(); $cart->user_id = Auth::check() ? Auth::user()->id : null; $cart->book_id = $request->id; $cart->quantity = $request->quantity; $cart->remember_token = $request->header('X-CSRF-TOKEN'); $check = $cart->save(); } if ($check) { return "true"; } else { return "Lỗi thêm hàng vào giỏ. Vui lòng thử lại!"; } } else { return "Quá số hàng trong kho. Vui lòng thử lại!"; } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $bookUpdate = Request::all(); $book = Book::find($id); $book->update($bookUpdate); return redirect('books'); }
/** * Proses order buku dari member. * * @return Response */ public function order($id) { if (Auth::user()->name) { $stock = Book::find($id)->stock; if ($stock > 0) { $user_id = Auth::user()->id; $checkBorrowCount = BookUser::whereUser_idAndStatus($user_id, 'pinjam')->count(); $checkOrderCount = BookUser::whereUser_idAndStatus($user_id, 'pesan')->count(); $checkCount = $checkBorrowCount + $checkOrderCount; if ($checkCount < 5) { $checkBorrow = BookUser::whereUser_idAndBook_idAndStatus($user_id, $id, 'pinjam')->count(); $checkOrder = BookUser::whereUser_idAndBook_idAndStatus($user_id, $id, 'pesan')->count(); if ($checkBorrow < 1 && $checkOrder < 1) { $book = Book::find($id); $book->stock -= 1; $book->save(); $data = new BookUser(); $data->user_id = $user_id; $data->book_id = $id; $data->status = 'pesan'; $data->save(); return redirect('/')->with('message', 'Berhasil memesan buku ' . $book->title); } else { return redirect('/')->withErrors('Hanya bisa memesan/meminjam 1 buku dengan judul yang sama.'); } } else { return redirect('/')->withErrors('Hanya bisa memesan/meminjam 5 buku'); } } else { return redirect('/')->withErrors('Stok buku kosong'); } } else { return redirect('/')->with('requiredName', $id); } }
public static function editBook($data, $id) { $book = Book::find($id); if ($data['title'] != '') { $book->title = $data['title']; } if ($data['isbn10'] != '') { $book->isbn10 = $data['isbn10']; } $author = new Author(); $genre = new Genre(); $author->name = $data['author']; $genre->name = $data['genre']; $authorToRemove = Author::find($data['authors']); $genreToRemove = Genre::find($data['genres']); $exisitngAuthor = Author::find($data['existing-author']); $exisitngGenre = Genre::find($data['existing-genre']); $book->authors()->detach($authorToRemove['author_id']); $book->genres()->detach($genreToRemove['genre_id']); $book->authors()->attach($exisitngAuthor['author_id']); $book->genres()->attach($exisitngGenre['genre_id']); if ($data['author'] != '') { $book->authors()->save($author); var_dump($data['author']); } if ($data['genre'] != '') { $book->genres()->save($genre); } $book->save(); }
public function update($id) { $user_id = \Request::input('user_id'); $checkBorrowCount = BookUser::whereUser_idAndStatus($user_id, 'pinjam')->count(); $checkOrderCount = BookUser::whereUser_idAndStatus($user_id, 'pesan')->count(); $checkCount = $checkBorrowCount + $checkOrderCount; if ($checkCount < 5) { $check = BookUser::whereUser_idAndBook_idAndStatus($user_id, $id, 'pinjam')->count(); if ($check < 1) { $book = Book::find($id); $book->stock -= 1; $book->save(); $data = new BookUser(); $data->user_id = $user_id; $data->book_id = $id; $data->status = 'pinjam'; $data->save(); return redirect('operator/transactions')->with('successMessage', 'Berhasil meminjam buku.'); } else { return redirect('operator/borrow')->with('errorMessage', 'User hanya bisa meminjam 1 buku dengan judul yang sama.'); } } else { return redirect('operator/borrow')->with('errorMessage', 'User Hanya bisa memesan/meminjam 5 buku'); } }
public function getBook($id) { $book = Book::find($id); if ($book == null) { return view('book')->with('message', 'Sorry, book not found.'); } return view('book')->with('book', $book); }
/** * Store a newly created resource in storage. * * @param CreateCartRequest|Request $request * @return Response */ public function store(CreateCartRequest $request) { $book = Book::find($request->bookId); $Quantity = $request->Quantity; Cart::add(['id' => $book->id, 'name' => $book->book_title, 'qty' => $Quantity, 'price' => $book->price, 'options' => array('size' => 'large')]); $cart = $this->getCartsContent(); return view('cart.index', compact('cart')); }
public function updateBook(Request $request, $id) { $Book = Book::find($id); $Book->title = $request->input('title'); $Book->author = $request->input('author'); $Book->save(); return response()->json($Book); }
/** * @return Redirect */ public function returnBook() { $bookId = Input::get('book_id'); $book = Book::find($bookId); $book->user_id = null; $book->taken = null; $book->save(); return redirect('books'); }
function getExample6() { //UPDATE $book = new Book(); $book_to_update = $book->find(1); $book_to_update->title = "TestCase"; $book_to_update->save(); $books = Book::orderBy('id', 'DESC')->get(); dump($books->toArray()); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(BookRegistrationRequest $request, $id) { $book = Book::find($id); $book->title = $request->title; $book->author = $request->author; $book->language = $request->language; $book->publication_date = $request->publication_date; $book->save(); return new JsonResponse(['msg' => 'OK'], 200); }
public function update($id) { $book = Book::find(\Request::input('book_id')); $book->stock += 1; $book->save(); $data = BookUsers::find($id); $data->status = \Request::input('status'); $data->save(); return redirect('operator/transactions'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $Book = \App\Book::find($id); if (is_null($Book)) { return response()->json(['msg' => 'success', 'Book' => 'Book not found'], 404); } if ($Book->delete()) { return response()->json(['msg' => 'success'], 200); } else { return response()->json(['msg' => 'error', 'error' => 'cannot update record'], 400); } }
public function addToCart() { session_start(); if ($_SESSION) { if ($_SESSION['cart']) { // dd($_SESSION); $rules = ['amount' => 'required|numeric', 'book' => 'required|numeric|exists:books,id']; foreach ($_SESSION['cart'] as $cart_item) { $validator = \Validator::make($cart_item, $rules); if ($validator->fails()) { return \Redirect::to('index')->with('error', 'book couldnt be added'); } dd(\Auth::user()->id); $member_id = \Auth::user()->id; $book_id = $cart_item['book']; $amount = $cart_item['amount']; $book = \App\Book::find($book_id); $total = $amount * $book->price; //checking existance and count in the cart $count = \App\Cart::where('book_id', '=', $book_id)->where('member_id', '=', $member_id)->count(); $cart = ['member_id' => $member_id, 'book_id' => $book_id, 'amount' => $amount, 'total' => $total]; \App\Cart::create($cart); } session_unset(); } } else { // dd('stop'); //VALIDATION // dd('s213s'); $rules = ['amount' => 'required|numeric', 'book' => 'required|numeric|exists:books,id']; $validator = \Validator::make(\Request::all(), $rules); if ($validator->fails()) { return Redirect::to('index')->with('error', 'book couldnt be added'); } $member_id = \Auth::user()->id; $book_id = \Request::get('book'); $amount = \Request::get('amount'); $book = \App\Book::find($book_id); $total = $amount * $book->price; //checking existance and count in the cart $count = \App\Cart::where('book_id', '=', $book_id)->where('member_id', '=', $member_id)->count(); // dd($count); // if ($count) // return \Redirect::to('index')->with('error', 'That book already exists in your cart'); $cart = ['member_id' => $member_id, 'book_id' => $book_id, 'amount' => $amount, 'total' => $total]; //uslovie esli ne avtorizovan to v sessiyu // \Session::push('cart.items', $cart); // dd(\Session::get('cart.items')); \App\Cart::create($cart); } return \Redirect::route('cart', compact($cart)); }
/** * Responds to requests to POST /books/edit */ public function postEdit(Request $request) { // Validation $book = \App\Book::find($request->id); $book->title = $request->title; $book->author_id = $request->author; $book->cover = $request->cover; $book->published = $request->published; $book->purchase_link = $request->purchase_link; $book->save(); \Session::flash('flash_message', 'Your book was updated.'); return redirect('/books/edit/' . $request->id); }
/** * * Tests updating of an existing book record and validates change in values * */ public function testProcessBookEdit() { //create a new book $book = new Book(); $book->title = 'Another Book About Php I think'; $book->author = 'Sherlock Holmes'; $book->save(); $bookEditURL = '/books/' . $book->id . '/edit'; //now update it $updatedTitle = 'No this is a JScript Book'; $updatedAuthor = 'Ali'; $this->visit($bookEditURL)->type($updatedTitle, 'title')->type($updatedAuthor, 'author')->press('Submit'); //confirm the values have been updated $updatedBook = Book::find($book->id); $this->assertEquals($updatedBook->title, $updatedTitle); $this->assertEquals($updatedBook->author, $updatedAuthor); }
public function saveBook(Request $request) { if ($request->book_id != "") { $book = Book::find($request->book_id); $book->title = $request->title; $book->genre_id = $request->genre_id; $book->author_id = $request->author_id; $book->publisher_id = $request->publisher_id; $book->image = $request->image; $book->isbn = $request->isbn; $book->description_short = $request->description_short; $book->description = $request->description; $book->price = $request->price; $book->sale = $request->sale; $book->quantity = $request->quantity; $check = $book->save(); if ($check) { return "EDIT_SUCCEED"; } else { return "Có lỗi xảy ra. Vui lòng thử lại sau!"; } } else { $book = new Book(); $book->title = $request->title; $book->genre_id = $request->genre_id; $book->author_id = $request->author_id; $book->publisher_id = $request->publisher_id; $book->image = $request->image; $book->isbn = $request->isbn; $book->description_short = $request->description_short; $book->description = $request->description; $book->price = $request->price; $book->sale = $request->sale; $book->quantity = $request->quantity; $check = $book->save(); if ($check) { $genre_name = Genre::find($request->genre_id)->name; $author_name = Author::find($request->author_id)->name; $data = array('msg' => 'ADD_SUCCEED', 'book_id' => $book->id, 'genre_name' => $genre_name, 'author_name' => $author_name); return $data; } else { return "Có lỗi xảy ra. Vui lòng thử lại sau!"; } } }
/** * Responds to requests to POST /books/edit */ public function postEdit(Request $request) { $book = \App\Book::find($request->id); $book->title = $request->title; $book->author_id = $request->author; $book->cover = $request->cover; $book->published = $request->published; $book->purchase_link = $request->purchase_link; $book->save(); if ($request->tags) { $tags = $request->tags; } else { $tags = []; } $book->tags()->sync($tags); \Session::flash('flash_message', 'Your book was updated.'); return redirect('/books/edit/' . $request->id); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { Book::find($id)->delete(); return redirect('books'); }
public function getDoDelete($book_id) { # Get the book to be deleted $book = \App\Book::find($book_id); if (is_null($book)) { \Session::flash('flash_message', 'Book not found.'); return redirect('\\books'); } # First remove any tags associated with this book // delete pivots if ($book->tags()) { $book->tags()->detach(); } # Then delete the book $book->delete(); # Done \Session::flash('flash_message', $book->title . ' was deleted.'); return redirect('/books'); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $book = Book::find($id); return view('books.show', compact('book')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $book = Book::find($id); $book->delete(); Session::flash('message', 'Successfully deleted book'); return Redirect::to('book'); }
//paypal Route::post('payment', array('as' => 'payment', 'uses' => 'PaypalController@postPayment')); // Después de realizar el pago Paypal redirecciona a esta ruta Route::get('payment/status', array('as' => 'payment.status', 'uses' => 'PaypalController@getPaymentStatus')); //carrinho Route::get('/cart/add/{product}', ['middleware' => 'auth.role:1', function ($product) { Session::push('cart.items', $product); return back(); }]); Route::get('/cart/clear', ['middleware' => 'auth.role:1', function () { Session::forget('cart'); return back(); }]); Route::get('/cart/show', ['middleware' => 'auth.role:1', function () { if (Session::has('cart.items')) { $books = \App\Book::find(Session::get('cart.items')); return view('cart/show', ['books' => $books]); } }]); Route::get('/cart/remove/{id}', ['middleware' => 'auth.role:1', function ($id) { foreach (Session::get('cart.items') as $key => $item) { if ($item == $id) { Session::forget('cart.items.' . $key); } } return back(); }]); Route::get('/historico', 'HomeController@getHistorico'); //backend Route::get('/backend/', ['middleware' => 'auth.role:4', function () { $books = App\Book::where('active', 0)->get();
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $book = Book::find($id); $book->user_id = null; $book->save(); Session::flash('message', 'Successfully deleted link user-book'); return Redirect::to('userbook'); }
public function edit($id) { $books = Book::find($id); return view('books.edit', compact('books')); }
public function removeBook($id) { $book = Book::find($id); $book->delete(); return Redirect::to('/'); }
/** * */ public function getDoDelete($book_id) { $book = \App\Book::find($book_id); if (is_null($book)) { \Session::flash('flash_message', 'Media not found.'); return redirect('\\books'); } if ($book->tags()) { $book->tags()->detach(); } $book->delete(); \Session::flash('flash_message', $book->title . ' was deleted.'); return redirect('/books'); }
/** * Deletes book from the db. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $book = Book::find($id); $title = $book->title; $author = $book->author; $id = $book->id; $book->delete(); Session::flash('message', "Successfully deleted book with the id:{$id} , title: {$title}, author: {$author} "); return Redirect::to(''); }
public function getDeleteborrower($id) { $validator = Validator::make(['id' => $id], ['id' => 'integer|min:0']); if ($validator->fails()) { return Redirect::back()->withErrors($Validator->messages()); } $borrowers = DB::select('select * from borrowers where id=?', [$id]); if (empty($borrowers)) { return Redirect::back()->withErrors("该图书不存在。"); } $borrower = Borrower::find($id); $book = Book::find($borrower->book_id); $book->count = $book->count + 1; if (!$book->save()) { return Redirect::back()->withErrors("归还图书失败!"); } $borrower->delete(); if (!$borrower->trashed()) { return Redirect::back()->withErrors("归还图书失败,请联系管理员!"); } return Redirect::back()->withInput(); }
/** * Add book to user with id * * @param $uid * @param $bid * @return Response */ public function addBook($uid, $bid) { $user = User::find($uid); $book = Book::find($bid); $user->books()->save($book); Session::flash('message', 'Book with ID: ' . $bid . ' successfully add to user with ID: ' . $uid); $this->sendReminderEmail($user, $book); return Redirect::to('books/users/' . $uid); }