This repository was archived by the owner on Jul 16, 2021. It is now read-only.

Description
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.