Search code examples
laravel-5eloquentlaravel-8laravel-models

How to make all column fillable by default of every newly created table in Laravel


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?


Solution

  • 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.