Ummm, need to add password to fillable probably.
illuminate3 said:
Ummm, need to add password to fillable probably. Still the same
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?
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...
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community