當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Book::findOrFail方法代碼示例

本文整理匯總了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'));
 }
開發者ID:aleximillers,項目名稱:estore-laravel-angular,代碼行數:7,代碼來源:BooksController.php

示例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);
     }
 }
開發者ID:jiqiang90,項目名稱:Laravel5-RESTful-API,代碼行數:19,代碼來源:BookController.php

示例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);
 }
開發者ID:maherelgamil,項目名稱:Small-store-for-books-with-Laravel-5.1,代碼行數:20,代碼來源:Book.php

示例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"];
     }
 }
開發者ID:PrakharSrivastav,項目名稱:bookbarterclub,代碼行數:22,代碼來源:BookController.php

示例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');
 }
開發者ID:arooth,項目名稱:Library-Management-System,代碼行數:16,代碼來源:PeminjamanController.php

示例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();
 }
開發者ID:atindermann08,項目名稱:readr,代碼行數:16,代碼來源:BookController.php

示例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);
 }
開發者ID:H3xept,項目名稱:uni-ingegneria,代碼行數:11,代碼來源:BookshelfController.php

示例8: returnBook

 public function returnBook($id)
 {
     $book = Book::findOrFail($id);
     $book['rented'] = 0;
     $book['user_id'] = -0;
     $book->update();
     return redirect('Books/rentedBooks');
 }
開發者ID:hossamElfar,項目名稱:libraryUpdated,代碼行數:8,代碼來源:BooksController.php

示例9: update

 public function update($id, BookRequest $request)
 {
     $book = Book::findOrFail($id);
     $book->update($request->all());
     return redirect('books');
 }
開發者ID:Qualenal,項目名稱:BooksWebsite,代碼行數:6,代碼來源:BooksController.php

示例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];
     }
 }
開發者ID:Korogba,項目名稱:mathlibrary,代碼行數:31,代碼來源:AdminController.php

示例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');
 }
開發者ID:maherelgamil,項目名稱:Small-store-for-books-with-Laravel-5.1,代碼行數:12,代碼來源:BooksController.php

示例12: destroy

 public function destroy($id)
 {
     $book = Book::findOrFail($id);
     $book->delete();
 }
開發者ID:NavyCoat,項目名稱:homework,代碼行數:5,代碼來源:BooksController.php

示例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();
開發者ID:unicodeveloper,項目名稱:eloquent-journey,代碼行數:31,代碼來源:routes.php

示例14: show

 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $BookRating = Book::findOrFail($id);
     $bookRating = $BookRating->getBookRating();
     return $bookRating;
 }
開發者ID:maherelgamil,項目名稱:Small-store-for-books-with-Laravel-5.1,代碼行數:12,代碼來源:RatingController.php

示例15: showBook

 public function showBook($id)
 {
     $book = Book::findOrFail($id);
     return View('book', compact('book'));
 }
開發者ID:AmirMehrabi,項目名稱:sabzName,代碼行數:5,代碼來源:PagesController.php


注:本文中的app\Book::findOrFail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。