Laravel 5 Mass Assignment, Guarded or Fillable?

Laravel 5 Mass Assignment, Guarded or Fillable?

SHARE

What is Fillable?

fillable lets you specify which fields is mass-assignable in your model. Lets take the above example, you can do it by adding the special variable $fillable to the model. So in the model:

As you have noticed, the ‘id, student_type‘ are not included, which means they are exempted.

Note: When ever you alter your table and add new field to it, don’t forget to add it into the $fillable variable if it is included in the white-list. “I experienced having trouble figuring out why the new field of my table is not saving, and just found out, I forgot to add it in the $fillable variable. I felt pity on my self that time. LOL.”

SHARE
Programmer, Database Designer and Administrator for Web Application. Who loves to read and write interesting topics.