本文整理汇总了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}");
}
示例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.');
}
示例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();
}
}
示例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.']);
}
示例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]);
}
示例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.');
}