简体   繁体   中英

MassAssignmentException in updateorcreate in laravel 5.4

I am newbie to laravel I am using updateorcreate for model. But this is showing error MassAssignmentException end_time In Model Tasktimelog I am using protected $guarded = array(); Here is what I am Doing.

$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
        ]);

Laravel doesn't let you to massive update fields of your database if you don't specificate it:

What you have to do is add the $fillable variable to your model with the fields that can be massively updated:

class Tasktimelog extends Model
{
    protected $fillable = ['task_id', 'action_type', 'user_id']; //and the rest of your fields
}

Laravel Doc: While $fillable serves as a "white list" of attributes that should be mass assignable, you may also choose to use $guarded. The $guarded property should contain an array of attributes that you do not want to be mass assignable.

https://laravel.com/docs/5.5/eloquent#eloquent-model-conventions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM