Laravel 5 Change Bulk Assignment

How can I change the fillable attribute of a model on the fly?

For example, I have a User model, protected $ fillable = ['name', 'email', 'password']

When updating a user, I want to exclude "email" from the bulk assignment so that it is not changed when updated.

+3


source to share


1 answer


Mass assignment does not mean that all fields listed in fillable

will be automatically filled in.

You still have control over what to save in the table.

So if you do:



$user = User::find(1);
$user->email = 'email@emails.com';
$user->save();

      

In the above example, only the email will be saved and the name and password remain the same

+1


source







All Articles