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