Pages

13 October, 2023

Since when did Laravel fill ONLY database fields into a Model?

I recently upgraded a Laravel application and came across some strange bugs. It turns out, the fill() method on models doesn't fill all fields anymore!

Yes, I'm aware of the $fillable and $guarded properties. In my model I don't have fillable set and have guarded set to ['id', 'created_at', 'updated_at']. So it should fill any properties except those three. In the past this worked fine, but now it only fills the fields that explicitly exist in the database. Laravel even runs a separate query to get those fields.

In my case, I had a "location" field with a dropdown and an "other" option to write in freetext. So the form would come with location=other and location_other=customtext. The DB would store "customtext" in the location field. But I can't fill the model and then copy "location_other" over, because the latter doesn't get filled.

When did this change? I never saw this listed anywhere in the documentation. submitted by /u/Disgruntled__Goat
[link] [comments]

No comments:

Post a Comment

Thanks