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


PHP Book::findOrFail方法代碼示例

本文整理匯總了PHP中Book::findOrFail方法的典型用法代碼示例。如果您正苦於以下問題:PHP Book::findOrFail方法的具體用法?PHP Book::findOrFail怎麽用?PHP Book::findOrFail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Book的用法示例。


在下文中一共展示了Book::findOrFail方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: update

 public function update($id)
 {
     $book = Book::findOrFail($id);
     $validator = Validator::make($data = Input::all(), $book->updateRules());
     if ($validator->fails()) {
         return Redirect::back()->withPesan('Terdapat kesalahan validasi')->withInput();
     }
     if (Input::hasFile('cover')) {
         $filename = null;
         $uploaded_cover = Input::file('cover');
         $extension = $uploaded_cover->getClientOriginalExtension();
         $filename = md5(time()) . '.' . $extension;
         $destination_path = public_path() . DIRECTORY_SEPARATOR . 'img';
         $uploaded_cover->move($destination_path, $filename);
         if ($book->cover) {
             $old_cover = $book->cover;
             $file_path = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $old_cover;
             try {
                 File::delete($file_path);
             } catch (FileNotFoundException $e) {
                 return Redirect::back()->withPesan('File tidak ditemukan')->withInput();
             }
         }
         $book->cover = $filename;
         $book->save();
     }
     // if (!$book->update(Input::except('cover'))) {
     if (!$book->update($data)) {
         return Redirect::back();
     }
     return Redirect::route('admin.books.index')->withPesan("Berhasil mengubah {$book->title}");
 }
開發者ID:ryanda,項目名稱:larapus,代碼行數:32,代碼來源:BooksController.php

示例2: postEdit

 public function postEdit($id)
 {
     $book = Book::findOrFail($id);
     $book->fill(Input::all());
     $book->save();
     return Redirect::action('BookController@getIndex')->with('flash_message', 'Your changes have been saved.');
 }
開發者ID:rebekahheacock,項目名稱:dwa15-archive,代碼行數:7,代碼來源:BookController.php

示例3: show

 public function show($id)
 {
     try {
         $book = Book::findOrFail($id);
         return $this->response->withItem($book, new BookTransformer());
     } catch (ModelNotFoundException $e) {
         return $this->response->errorNotFound();
     }
 }
開發者ID:erpmesh,項目名稱:erphub,代碼行數:9,代碼來源:ErpInsController.php

示例4: update

 /**
  * Update the specified resource in storage.
  * PUT /branch/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $inputs = Input::all();
     $book = Book::findOrFail($id);
     $book->fill($inputs);
     if ($book->save()) {
         return Redirect::to('/libros/' . $id)->with('alert', ['type' => 'success', 'message' => 'Datos guardados.']);
     }
     return Redirect::to('/libros/' . $id)->with('alert', ['type' => 'danger', 'message' => 'Ocurrio un error, intenta mas tarde.']);
 }
開發者ID:pombredanne,項目名稱:licenser-7,代碼行數:17,代碼來源:LicenseController.php

示例5: show

 /**
  * Get a single book
  *
  * @param $book_id
  * @return Response
  */
 public function show($book_id)
 {
     $book = Book::findOrFail($book_id);
     return Response::json(['data' => $book]);
 }
開發者ID:nguyen-tien-mulodo,項目名稱:packback-rest-api-101,代碼行數:11,代碼來源:BookController.php

示例6: postDelete

 /**
  * Process book deletion
  *
  * @return Redirect
  */
 public function postDelete()
 {
     try {
         $book = Book::findOrFail(Input::get('id'));
     } catch (exception $e) {
         return Redirect::to('/book/')->with('flash_message', 'Could not delete book - not found.');
     }
     Book::destroy(Input::get('id'));
     return Redirect::to('/book/')->with('flash_message', 'Book deleted.');
 }
開發者ID:rebekahheacock,項目名稱:dwa15-archive,代碼行數:15,代碼來源:BookController.php


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