You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
When casting an Eloquent model attribute to a 'collection', if the value is currently null, the cast does not take place, and null is returned.
To avoid having to litter the code with existence tests for that attribute, and also be consistent with relationships, I propose an empty collection be returned instead.
On the saving side, there could also be logic to save an empty collection as null, but this is not critical.
Unfortunately this would be a breaking change. Any existence check e.g. if ($model->collection) would need to be changed to if ($model->collection->isEmpty()), but in many of those cases, I suspect the check would no longer be necessary.
The text was updated successfully, but these errors were encountered:
null and empty collection can legitimately mean different things.
For example, a null value in the database can indicate that a user hasn't selected any preferences yet, while an empty collection can indicate that a user has specifically stated they have no preferences.
If in your app null and empty collection mean the same thing, I suggest making the default value of the column an empty collection rather than null.
When casting an Eloquent model attribute to a 'collection', if the value is currently null, the cast does not take place, and null is returned.
To avoid having to litter the code with existence tests for that attribute, and also be consistent with relationships, I propose an empty collection be returned instead.
On the saving side, there could also be logic to save an empty collection as null, but this is not critical.
Unfortunately this would be a breaking change. Any existence check e.g.
if ($model->collection)
would need to be changed toif ($model->collection->isEmpty())
, but in many of those cases, I suspect the check would no longer be necessary.The text was updated successfully, but these errors were encountered: