Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

llioor's avatar

fillable, hidden and guarded

Hello everybody, I'd like to know if someone can help me with a question.

We can find here explanation on mass assignment. The example is about guarding the "is_admin" property against user hacking and changing it to "1" from "0" without the permission for it. https://laravel.com/docs/5.1/eloquent#mass-assignment

So why here: https://github.com/laravel/laravel/blob/master/app/User.php "password" is under "fillable & hidden" attributes and not under "guarded" attribute if we wont to avoid from the user to change the password manually?

Thanks, Leo.

0 likes
5 replies
Jaytee's avatar

Essentially, the only person that should be able to change the "is_admin" property is an admin, if the password wasn't fillable, they wouldn't be able to register.

Snapey's avatar

both are wrong. a value that is not fillable can still be set directly, as in $user->password=x

llioor's avatar

@Snapey The thing is that we did not ask if "a value that is not fillable can still be set directly"... I asked about that even in registration we can add specific action for changing password so why not to add passwords to "guarded" attribute..

Snapey's avatar
Snapey
Best Answer
Level 122

I agree, its open for question. I was replying to comments by @jaytee and someone else that has since removed their post.

I can't though think of a plausible exploit since it is not possible for an outsider to come up with a password that can work unless they also know the key for the hashing algorithm. Therefore, the best an attacker could do is create a denial of service to an individual user. Now, if this denial then leads to the user requesting a password reset, then the attacker might be able to then exploit some other vulnerability.

1 like
jekinney's avatar

All three methods are essentially elequent only. Basically you're setting defaults to protect yourself.

Hidden will not return that column on an eloquent get query.

Fillable and guarded are essentially opposite of each other. Your "safe" with one or the other. Generally most just use fillable.

If you manually new up a class or use the db query builder you will bypass those methods but you should have everything set explicitly.

Both cases a user can't override with form or Ajax input.

Please or to participate in this conversation.