Here's an S.O. article that explains:
https://stackoverflow.com/questions/22279435/what-does-mass-assignment-mean-in-laravel
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I'm new to Laravel. I learned how to solve the issue with the MassAssignmentException, however I do not understand why such a concept was introduced. Here is for example what's inside my Posts controller :
Post::create([
'title' => request('title'),
'body' => request('body')
]);
As you can see, I clearly say I want to INSERT the title and the body. Why, ON TOP OF THAT, do I need to define what's fillable or guarded? Why such a redundancy?
Also, are the "created_at" and "updated_at" columns of my DB immune by default, or can a hacker forge a POST request to alter both those columns as well?
Thank you for your time.
For one thing, a lot of people like to just use Post::create($request->all()) for simplicity instead of naming out each individual parameter, which introduces security concerns. What if I added is_admin=1 to the post request and there happened to be an is_admin field? It would just set it.
There is also the $guarded parameter to play with, which is a blacklist instead of the $fillable whitelist. you can just do $guarded = [] and not worry about having to set fields in $fillable every time. If you're explicitly naming what you're saving each time (like your example), that's what I'd do. Laravel is just flexible and allows you to work in different ways depending on how you want to do things.
Please or to participate in this conversation.