Mass assignment is the process of sending an array of data that will be stored in the specified model at a time. As a rule, you do not need to save data in your model separately, but rather in one process.
Bulk assignment is good, but there are certain security issues behind it. What to do if someone passes the value to the model and without protection can definitely change all fields, including the identifier. This is not good.
Suppose you have a table of "students", with the fields "student_type, first_name, last_name" . You might want to bulk assign "first_name, last_name", but you want to protect student_type from changing directly. Where it is filled and guarded .
Fillable allows you to specify which fields can be assigned by mass in your model, you can do this by adding the special variable $fillable to the model. So in the model:
class Student extends Model { protected $fillable = ['first_name', 'last_name'];
'student_type' are not included, which means they are freed.
It is protected from the back. If the fillable parameter indicates which fields should be assigned by mass, the guardiled parameter indicates which fields cannot be assigned by mass. So in the model:
class Student extends Model { protected $guarded = ['student_type'];
You should use either $ fillable or $ guarded - but not both.
For more information, open the link: - Mass assignment
Udhav Sarvaiya Apr 05 '18 at 10:12 2018-04-05 10:12
source share