Support the ongoing development of Laravel.io →
Authentication Eloquent
Last updated 1 year ago.
0

Ummm, need to add password to fillable probably.

Last updated 1 year ago.
0

illuminate3 said:

Ummm, need to add password to fillable probably. Still the same

Last updated 1 year ago.
0

Only way I can think of would be overriding the methods responsible for fetching results from db, but the question is WHY you want to do that?

Last updated 1 year ago.
0

jarektkaczyk said:

Only way I can think of would be overriding the methods responsible for fetching results from db, but the question is WHY you want to do that?

Just studying Laravel and therefore cant understand for what $fillable and $guarded are done if they not working properly...

Last updated 1 year ago.
0

trololosha4real said:

jarektkaczyk said:

Only way I can think of would be overriding the methods responsible for fetching results from db, but the question is WHY you want to do that?

Just studying Laravel and therefore cant understand for what $fillable and $guarded are done if they not working properly...

Fillable and Guarded are used to prevent mass assignment vulnerabilities. They don't prevent you from accessing the individual properties normally.

For example, without a $fillable or $guarded, the following code would throw an exception:

$input = Input::all();
User::create($input);

Because doing this with user form input means they could alter the form's html and update values you didn't intend.

The hidden attribute defines what values aren't included when you convert the object to JSON.

Last updated 1 year ago.
0

trololosha4real said:

jarektkaczyk said:

Only way I can think of would be overriding the methods responsible for fetching results from db, but the question is WHY you want to do that?

Just studying Laravel and therefore cant understand for what $fillable and $guarded are done if they not working properly...

Fillable and guarded are supposed to do totally different job as stated before.

Hidden and visible on the other hand are the ones to talk about in this case.

However, you don't want NOT to return values from db, as it's not how ORM works, right? The idea behind visible/hidden properties is that you never show them in toJson and toArray results (which are called on the Model/Collection by default when __toString is needed). Still you can access them manually like you tried, and that is rather right behaviour.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.