Reputation: 41
I have some code producing the following error. How can I fix it?
BookController
public function bookedit(Request $req,$id){
$this->middleware('admin');
$edit = Book::where('bookID','=',$id)->first();
$edit->bookName = $req->input('bookName');
$edit->author = $req->input('author');
$edit->categoryID = $req->input('categoryID');
$edit->nxb = $req->input('nxb');
$edit->description = $req->input('description');
$edit->price = $req->input('price');
$edit->update();
return redirect()->back()->withErrors(['msg', 'Sua thanh cong']);
}
Of course my primary key in Book.php is bookID not id so why do id column appear here???
Upvotes: 1
Views: 764
Reputation: 8618
In you Book
model define
class Book extends Model
{
protected $primaryKey = 'bookID';
......
}
Upvotes: 2