本文整理汇总了PHP中app\Book::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::findOrFail方法的具体用法?PHP Book::findOrFail怎么用?PHP Book::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Book
的用法示例。
在下文中一共展示了Book::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($id)
{
$product = Book::findOrFail($id);
$images = $product->images;
$authors = $product->Author;
return view('books.book', compact('product', 'images', 'authors'));
}
示例2: update
/**
* 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);
}
}
示例3: smallDescription
/**
* 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);
}
示例4: update
/**
* 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"];
}
}
示例5: pengembalian
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');
}
示例6: removeFromLibrary
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();
}
示例7: show
/**
* 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);
}
示例8: returnBook
public function returnBook($id)
{
$book = Book::findOrFail($id);
$book['rented'] = 0;
$book['user_id'] = -0;
$book->update();
return redirect('Books/rentedBooks');
}
示例9: update
public function update($id, BookRequest $request)
{
$book = Book::findOrFail($id);
$book->update($request->all());
return redirect('books');
}
示例10: getObjAndTotal
/**
* 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];
}
}
示例11: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$Book = Book::findOrFail($id);
$Book->delete();
return redirect('books');
}
示例12: destroy
public function destroy($id)
{
$book = Book::findOrFail($id);
$book->delete();
}
示例13: function
$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();
示例14: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$BookRating = Book::findOrFail($id);
$bookRating = $BookRating->getBookRating();
return $bookRating;
}
示例15: showBook
public function showBook($id)
{
$book = Book::findOrFail($id);
return View('book', compact('book'));
}