Mass assignment allows multiple model attributes to be assigned from an array, for example:
Product::create([
'name' => $data['name'],
'price' => $data['price'],
]);
Laravel provides protection mechanisms so developers explicitly define which attributes may be mass assigned or otherwise control assignment behavior.
A common risk is accepting arbitrary request data:
Model::create($request->all());
Scenario:
If a users table contains an administrative flag, blindly accepting request data could allow a malicious client to submit fields that should never be user-controlled.
Interview tip:
Explain why validated data and explicit model assignment are important security boundaries.
0 comments:
Post a Comment
Thanks