本文整理匯總了PHP中app\Book::find方法的典型用法代碼示例。如果您正苦於以下問題:PHP Book::find方法的具體用法?PHP Book::find怎麽用?PHP Book::find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Book
的用法示例。
在下文中一共展示了Book::find方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addCart
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!";
}
}
示例2: update
/**
* 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');
}
示例3: order
/**
* 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);
}
}
示例4: editBook
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();
}
示例5: update
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');
}
}
示例6: getBook
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);
}
示例7: store
/**
* 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'));
}
示例8: updateBook
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);
}
示例9: returnBook
/**
* @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');
}
示例10: Book
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());
}
示例11: update
/**
* 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);
}
示例12: update
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');
}
示例13: destroy
/**
* 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);
}
}
示例14: addToCart
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));
}
示例15: postEdit
/**
* 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);
}