The mass assignment may be a method of causing an array of information which will be saved to the required model directly. In general, you do not have to save data on your model on one by one basis, however rather in a very single method.

Mass assignment is nice, however, there are bound security issues behind it. What if somebody passes a value to the model and while not protection they will positively modify all fields as well as the ID. That’s not sensible.

What is fillable?

Using models is one of the best facts in Laravel, but when using a model, it has three variables, and one of them is “fillable”.You can define those fields which can be created/ filled by mass-assignment by use of fillable.

For example, let’s say you have a user model with:

And for your registration logic you have something like:

They put protected $fillable = [‘name’, ‘email’, ‘password’]; which means we’ve got rid of the id. But the word fillable means something we can fill and it makes sense since the ID is auto-incremented,

What is Guarded?

Guarded is that the reverse of fillable. If fillable specifies that fields to be mass assigned, guarded specifies that fields don’t seem to be mass assignable.


Dona Elsa

Written by

Dona Elsa