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}"); }
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.'); }
public function show($id) { try { $book = Book::findOrFail($id); return $this->response->withItem($book, new BookTransformer()); } catch (ModelNotFoundException $e) { return $this->response->errorNotFound(); } }
/** * 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.']); }
/** * Get a single book * * @param $book_id * @return Response */ public function show($book_id) { $book = Book::findOrFail($book_id); return Response::json(['data' => $book]); }
/** * 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.'); }