You need to use the protected $fillable
, assigning it an array of fields / columns that you want to fill / assign values. For example, you have a model with fields f1, f2, f3 and f4
. You want to assign the values f1, f2 and f3 but not to f4
, then you need to use:
protected $fillable = ['f1', 'f2', 'f3'];
The above line will allow you to pass an array:
$mod = Model::create($arr); $mod->save();
Regardless of the $ arr array, only f1, f2, and f3
will be assigned values โโ(if the values โโexist in the $arr array for f1, f2, f3
).
Hope this helps you and others.
source share