Majeed
219
4
Laravel

Convert a collection or object to an array

Posted 6 months ago by Majeed

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? **

Please sign in or create an account to participate in this conversation.