Recall & Review
beginner
What is mass assignment in Laravel?
Mass assignment is a way to set multiple model attributes at once using an array, often when creating or updating a model.
Click to reveal answer
beginner
Why is mass assignment protection important?
It prevents users from setting sensitive or unintended fields by restricting which attributes can be filled in bulk, protecting your app from security risks.
Click to reveal answer
beginner
What property do you use in a Laravel model to allow mass assignment on specific fields?
You use the
$fillable property to list the attributes that are allowed to be mass assigned.Click to reveal answer
intermediate
What happens if you try to mass assign attributes not listed in
$fillable?Laravel will ignore those attributes and not set them on the model, protecting your app from unwanted changes.
Click to reveal answer
intermediate
What is the
$guarded property in Laravel models?$guarded is the opposite of $fillable. It lists attributes that should NOT be mass assignable. Setting it to an empty array means all attributes are mass assignable.Click to reveal answer
Which property in a Laravel model defines which attributes can be mass assigned?
✗ Incorrect
The $fillable property lists the attributes allowed for mass assignment.
What will happen if you try to mass assign an attribute not in $fillable?
✗ Incorrect
Laravel silently ignores attributes not in $fillable to protect your app.
If you want to allow all attributes to be mass assignable, what should you set $guarded to?
✗ Incorrect
Setting $guarded to an empty array means no attributes are guarded, so all are mass assignable.
Mass assignment protection helps prevent what kind of security issue?
✗ Incorrect
Mass assignment protection prevents users from changing sensitive fields they shouldn't.
Which method commonly uses mass assignment in Laravel?
✗ Incorrect
Model::create() accepts an array of attributes and uses mass assignment to set them.
Explain mass assignment protection in Laravel and how to use $fillable and $guarded properties.
Think about how you control which fields users can set when creating or updating data.
You got /5 concepts.
Describe a real-life example where mass assignment protection prevents a security risk in a Laravel app.
Imagine a user trying to make themselves an admin by sending extra data.
You got /4 concepts.