Why Do We Use Fillable In Laravel?

Why Do We Use Fillable In Laravel?

Why Do We Use Fillable In Laravel?

The "fillable" property defines which fields of a model can be mass-assigned when using the create or update method. 

– It's a security measure to prevent unauthorized updates of fields in the database.

In other words, it allows you to explicitly declare which fields can be saved in the database using the mass assignment.

For example, if you have a User model with a fillable property that consists of only the "name" and "email" fields:

class User extends Model
{
    protected $fillable = ['name', 'email'];
}

– It means that when you call User::create or $user->update and pass an array of data, only the "name" and "email" fields will be updated in the database.

All Comments