In Laravel 8 Backend app with output
$var->toArray())
if $var is collection of models, then array of model values is outputted
But if $var - is array, which generated as :
$permissions = Permission
::orderBy('name', 'asc')
->get()
->map(function ($permissionItem) use ($userPermissions) {
return $permissionItem;
})
->all();
$permissions - would be array of models. Can I to convert it into collection and use toArray() to it ?
Thanks!
mapcall isn't actually doing anything->toArray()at all; a Collection is perfectly fine, and will be converted to JSON from your backend (for example, or remain as a Collection, both of which are fine)$permissions = Permission::orderBy('name', 'asc')->get();is already a collection.