29

I have around 200 fields in a table that are numbered:

field_1
field_2
etc

I tried to insert data in table:

Result::insert($data);

Where $data is multiple array:

$data = [] = array("field_1" => 3);
$data = [] = array("field_1" => 2);

Can I set * in option protected $fillable = ["*"]; to make all fields fillable?

Simon.B
  • 70
  • 1
  • 8
Griboedov
  • 413
  • 1
  • 6
  • 12

2 Answers2

50

If you need to set all columns as fillable, do this in the model:

protected $guarded = [];

If you would like to make all attributes mass assignable, you may define the $guarded property as an empty array

https://laravel.com/docs/5.3/eloquent#mass-assignment

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
27

In such scenario, you can try doing the reverse. For example: id, created_at and updated_at field as $guarded. Like:

protected $guarded = ['id', 'created_at', 'updated_at'];

Except these rest will be considered as fillable i.e. mass assignable.

You can find details in Official Laravel Doc

Guarding Attributes

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. All other attributes not in the array will be mass assignable. So, $guarded functions like a "black list". Of course, you should use either $fillable or $guarded - not both.

Mahfuzul Alam
  • 3,057
  • 14
  • 15