我有一張運動隊的桌子。記錄顯示團隊選擇和其他一些信息。我想用團隊選擇更新記錄。我的模型是這樣的:使用Laravel模型的更新表格
class Selection extends Model {
protected $table = "selection";
protected $fillable = [
'loose',
'hooker',
'tight',
'secrow1',
'secrow2',
'blindflank',
'openflank',
'eight',
'scrum',
'fly',
'leftwing',
'rightwing',
'fullback',
'sub1',
'sub2',
'sub3',
'sub4',
'sub5'
];
}
所以我有一個形式,給出了位置的所有數據,並給出了ID在數據庫中記錄。在我的控制,我有:
public function storeFirstTeam()
{
$input = Request::all();
Selection::update($input->id,$input);
return redirect('first-team');
}
,但我得到了以下錯誤:
Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically, assuming $this from incompatible context
任何人都可以指出我的傻錯誤?
您必須先選擇要更新的行。當您發佈更新請求時,如何獲得選擇的「id」? –
嘗試像這樣:'Selection :: whereId($ id) - > update($ request-> except(['_ method','_ token']));' –