Level 6
->toArray()
??
This is my query:
$data=Auth::user()->roles()->with('permissions')->get()->pluck('permissions');
return $data;
The output of the query is as following:
[
[
{
id: 2,
name: "Read",
slug: "Read",
description: "This is Simple Read Permission",
pivot: {
role_id: 2,
permission_id: 2,
},
},
{
id: 3,
name: "Update",
slug: "Update",
description: "This is Simple Update Permission",
pivot: {
role_id: 2,
permission_id: 3,
},
},
]
]
**How can I convert this collection in to an array? **
$data=Auth::user()->roles()->with('permissions')->get()->pluck('permissions')->flatten();
This will remove the "double" array, as you're getting a collection of roles and then plucking 'permissions' which returns an array itself.
Please or to participate in this conversation.