我是个新手,我正在使用updateorcreate for model。但这在模型任务时间日志中显示了错误数组,我正在使用MassAssignmentException $guarded = end_time ();这就是我正在做的事情。
$endtask= Tasktimelog::updateOrCreate(
[
'task_id' => $taskid,
'action_type'=>4,
'user_id'=> auth()->id()
],
[
'end_time' => $endtimeis,
'total_time' => request('totalseconds'),
'remark' => request('remark'),
'actual_complete_time' => $diff,
'project_id' => $getprojectid->project_id
]);发布于 2019-05-29 18:15:04
Laravel不允许你大量更新数据库的字段,如果你不指定它的话:
您需要做的是将$fillable变量添加到您的模型中,其中包含可以大规模更新的字段:
class Tasktimelog extends Model
{
protected $fillable = ['task_id', 'action_type', 'user_id']; //and the rest of your fields
}$guarded :虽然$fillable是一个应该批量分配的属性的“白名单”,但您也可以选择使用Laravel。$guarded属性应包含不希望批量赋值的属性数组。
https://laravel.com/docs/5.5/eloquent#eloquent-model-conventions
https://stackoverflow.com/questions/47364157
复制相似问题