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

Description
Love being able to have DB JSON types cast to arrays using the 'json' $casts property.
One thing I noticed was that because arrays are always copied (rather than referenced), you end up with verbose code when you want to mutate the value:
$something->json_backed_attribute = array_merge($something->json_backed_attribute, [
MyEnum::MY_CONST => [
'some-thing' => "doesn't matter",
],
]);
This got me thinking that it would be great if there was something like a json_collection cast that returned an instance wrapped by collect().
Benefits:
- Feature is still opt-in
- The value is now passed by reference rather than copied
- You can now do this:
$something->json_backed_attribute->merge([]);
Love it? Hate it? It was just a thought I had this morning... 😄