Jun 15, 2021
4
Level 1
How to collapse this collection
I am using Laravel-permission on a ChatParticipants (all participants of a chat) model.
Now every participants have specifc roles/permissions.
Here is my query participants on my Chat model:
public function participants()
{
return $this->hasMany(ChatParticipant::class, 'chat_id', 'id')->with([
'details',
'roles' => function ($q) {
$q->select('name');
},
'permissions' => function ($q) {
$q->select('name');
}
]);
}
my current output is this:
-Chats
-Participants
-Roles: [ 0 => {name: "role1"}, 1 => {name: "role2"} ]
-Permissions: [ 0 => {name: "permission1"}, 1 => {name: "permission2"} ]
How can I collapse the Roles and Permissions where it would look like this:
-Chats
-Participants
-Roles: [ "role1", "role2" ]
-Permissions: [ "permission1", "permission2" ]
Please or to participate in this conversation.