本文整理匯總了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.');
}