我必须从Eloquent代码中选择1个表1行
$ReceiveDetailSelected = ReceiveDetail::where([['subjectid', $subject],['psubid', $request->psubid],['id', $id]])->first();
return $ReceiveDetailSelected;
和结果
{"no":1,"id":1,"psubid":"1\/2017","pdetailid":"1","subjectid":"7","labid":"1","result":0,"path_file":"3","status":"pending","created_at":"2017-08-14 13:27:59","updated_at":"2017-08-14 15:19:39","deleted_at":null}
但在数据库中更新代码
中的所有行$ReceiveDetailSelected = ReceiveDetail::where([['subjectid', $subject],['psubid', $request->psubid],['id', $id]])->first();
$ReceiveDetailSelected->status = 'pending';
$ReceiveDetailSelected->path_file = '4';
$ReceiveDetailSelected->save();
return $ReceiveDetailSelected;
功能中的完整代码
public function storenewwork($id,$subject,$product,Request $request)
{
$ReceiveDetailSelected = ReceiveDetail::where([['subjectid', $subject],['psubid', $request->psubid],['id', $id],['no', '1']]);
$ReceiveDetailSelected->status = 'pending';
$ReceiveDetailSelected->path_file = '4';
$ReceiveDetailSelected->save();
return $ReceiveDetailSelected;
}
答案 0 :(得分:0)
我通过添加protected $primaryKey = 'no';
解决了我认为laravel已将pk设置为id
。它将更新id= 1