PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 3, 2022

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

 March 03, 2022     eloquent, laravel-5, laravel-8, laravel-models     No comments   

Issue

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.



Answered By - Akash Kumar Verma
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing