map(function ($value) { if (is_array($value) || is_object($value)) { return (new \Illuminate\Support\Collection($value))->recursive(); } return $value; }); }); \Illuminate\Support\Collection::macro('toObject', function () { return $this->map(function ($value) { if (is_array($value) || is_object($value)) { return (object) \json_decode(\json_encode($value)); } return $value; }); }); \Illuminate\Support\Collection::macro('object', function () { return \json_decode(\json_encode($this)); }); } }