Recursively wrap nested arrays in Laravel-style DTO objects and collections. Just pass in your array and BLAMO, you'll get a nested DTO objects and collections back.
I like accessing data in my views using a fluent object syntax instead of array syntax.
$data = objection(
[
[
'test' => 'asdf',
'test2' => [
'sub' => 'asdasdffasdf',
'sub2' => 'teasdasdffasdfst',
],
],
[
'test' => 'asdasdffasdf',
'test2' => 'teasdasdffasdfst',
]
]
)
echo $data->first()->test2->sub2; //teasdasdffasdfst
$data->toArray();
return \Incraigulous\Objection\ObjectionFactory::make($array);
composer require incraigulous/objection
- DTO Objects: https://github.com/schulzefelix/laravel-data-transfer-object
- Collections: https://laravel.com/docs/5.7/collections