I'm trying to get the ID of eloquent for editing its columns, but when I make the changes in the column in edit page and click done it returns this error. Call to a member function fill() on string
When I use the code dd($id);
it returned the word 'update' on dd page.
Route
Route::group(['prefix' => 'admin/books'], function($book){
Route::get('edit/{id}','BookController@getUrlBook')->middleware('auth');
Route::post('edit/{book}','EditController@update')->middleware('auth');
Route::get('edit/{id}','BookController@getUrlBook', function ($book) {
return view('edit',[
'id' => $book->id,
'name' => $book->name,
'writer' => $book->writer_name,
'isbn' => $book->isbn,
]);
})->middleware('auth');
Route::post('create','EditController@create');
Route::get('create', function () {
return view('create');
})->middleware('auth');
});
Controller
public function update(Request $request,$id){
$this->middleware('auth');
$imgExtensions = ['jpg','png','svg'];
$id->fill($request->only(['name','writer_name','isbn']));
if(null !== $request->book_image && in_array($request->file('book_image')->getClientOriginalExtension(), $imgExtensions )){
$id->image = $request->file('book_image')->storeAs('images', $request->id.'.jpg');
}
$id->save();
return redirect('/admin');
}