0

In each Laravel model, I want to declare fillable like the following.

protected $fillable = [
    'object_name','attributes','item','cost','status','category',
    'object_id','status','customer_id','provider_id'
       
];

After that, I can insert value in the database. Is there any way to make all columns of every newly created table fillable, or will I need to change it every time?

Akash Kumar Verma
  • 3,185
  • 2
  • 16
  • 32
  • 1
    Create a class and extend the base `Eloquent` by overriding the `protected $fillable = ['*']`. Now just create a new command for generating a model from the newly created class. However, I think I will consider this as bad practice since I am not in favor of that. – Basheer Kharoti Dec 26 '20 at 13:40

1 Answers1

7

you can use guarded property in model class;

protected $guarded = [];

after adding this line you don't need to define fillable array in model class. so remove that property

$fillable serves as a "white list" whereas $guarded serves like a "black list". One should use either $fillable or $guarded.

Akash Kumar Verma
  • 3,185
  • 2
  • 16
  • 32