Laravel 5 Mass Assignment, Guarded or Fillable?

Laravel 5 Mass Assignment, Guarded or Fillable?

SHARE
What is mass assignment? Will you use fillable or guarded?

Mass assignment is a process of sending an array of data that will be saved to the specified model at once. In general, you don’t need to save data on your model on one by one basis, but rather in a single process.

Mass assignment is good, but there are certain security problems behind it. What if someone passes value to the model and without protection they can definitely modify all fields including the ID. That’s not good.

Let’s say you have ‘students‘ table, with fields “student_type, first_name, last_name, birthdate, sex“. You may want to mass assign “first_name, last_name, birthdate, sex” but you want to protect student_type from being directly changed. That’s where fillable and guarded take into place.

Prev1 / 4

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