Mark all fields fillable in model
HI,
is there command to set all data fillabe in model ?
I try with :
protected $fillable = array('*');
but not work,
tnx,
p
protected $guarded = ['id'];
As you probably dont want id to be mass assignable (you should).
Hi pmail,
I found this in documentation , just like to know for any other possibility...
Tnx bro:)
@pavlen no that's it. What else would you want?
I agree with @pmall above - why would you ever want to specify the table.id? But to answer the exact question - you can use
protected $guarded = [];
to make ALL columns fillable.
I have specified the id in migration documents where I want a row have a specific ID.
I know I am just being picky....
@pavlen
If you would like to make all attributes mass assignable, you may define the $guarded property as an empty array
according to document
You should try this:
protected $fillable = ['id','name','email'];
OR
remove protected $fillable from model then all fields available for fillable
It's worth to note, that un-guarding all the fields won't allow you to do
Model::create(request()->all());
because it may not find some fields in your database table.
Thank you! Migration is exactly the case I needed this for.
Please or to participate in this conversation.