Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pavlen's avatar

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

0 likes
9 replies
pmall's avatar
protected $guarded = ['id'];

As you probably dont want id to be mass assignable (you should).

13 likes
pavlen's avatar

Hi pmail,

I found this in documentation , just like to know for any other possibility...

Tnx bro:)

autefrum's avatar

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

5 likes
Palak27's avatar

@pavlen

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

according to document

AddWebContribution's avatar

You should try this:

protected $fillable = ['id','name','email'];

OR

remove protected $fillable from model then all fields available for fillable

SergiuSvet's avatar

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.

shawnhooper's avatar

Thank you! Migration is exactly the case I needed this for.

Please or to participate in this conversation.