我有一些代码会产生以下错误。我该如何解决?
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']);
}
当然,我在Book.php中的主键是 bookID 而不是 id 那么为什么 id 列会显示在这里???
答案 0 :(得分:2)
在您Book
模型中定义
class Book extends Model
{
protected $primaryKey = 'bookID';
......
}