php - Method [all] does not exist in Laravel 5.2 -
just issues bothering me. error in code after validator::make in update function.
badmethodcallexception in controller.php line 107: method [all] not exist.
this full code bookscontroller
<?php namespace app\http\controllers; use illuminate\http\request; use illuminate\support\facades\validator; use illuminate\support\facades\input; use illuminate\support\facades\redirect; use app\http\requests; use app\http\controllers\controller; use app\book; class bookscontroller extends controller { /** * display listing of resource. * * @return response */ public function index() { $book = bookscontroller::all(); return view('book.index')->with('book', $book); } /** * show form creating new resource. * * @return response */ public function create() { return view('book.create'); } /** * store newly created resource in storage. * * @return response */ public function store() { $rules = array( 'judul' => 'required', 'author' => 'required', 'penerbit' => 'required' ); $validator = validator::make(input::all(), $rules); // process login if ($validator->fails()) { return redirect::to('book/create') ->witherrors($validator) ->withinput(input::except('password')); } else { // store $book = new book; $book ->judul = input::get('judul'); $book ->author = input::get('author'); $book ->penerbit = input::get('penerbit'); $book ->save(); // redirect session:flash('message', 'berhasil membuat buku!'); return redirect::to('book'); } } /** * display specified resource. * * @param int $idate * @return response */ public function show($id) { $book = books::find($id); return view('book.show') ->with('book', $book); } /** * show form editing specified resource. * * @param int $id * @return response */ public function edit($id) { $book = books::find($id); return view('book.edit') ->with('book', $book); } /** * update specified resource in storage. * * @param int $id * @return response */ public function update($id) { $rules = array( 'judul' => 'required', 'author' => 'required', 'penerbit' => 'required' ); $validator = validator::make(input::all(), $rules); if ($validator->fails()) { return redirect::to('book/' . $id . '/edit') ->witherrors($validator) ->withinput(input::except('password')); } else { // simpan $book = books::find($id); $book->judul = input::get('judul'); $book->author = input::get('author'); $book->penerbit = input::get('penerbit'); $book->save(); // redirect session::flash('message', 'berhasil mengganti info buku!'); return redirect::to('book'); } } /** * * @param int $id * @return response */ public function destroy($id) { $book = books::find($id); $book ->delete(); //redirect session::flash('message', 'berhasil menghapus buku!'); return redirect::to('book'); } }
try use validator;
instead of use illuminate\support\facades\validator;
convert user input::all()
input()->all()
or request()->all()
Comments
Post a Comment