当前位置: 首页>>代码示例>>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;未经允许,请勿转载。