Search code examples
phplaravelmodellaravel-permission

How to list all roles with Permissions,in spatie permission Package?


I'm using spatie package for roles and permissions in my laravel project, I need to list all roles with their permissions in a table, is there is any way?

[  
   {  
      id:1,
      name:"role1",
      "permissions":[  
         {  
            "id":1,
            "name":"Permission 1"
         },
         {  
            "id":2,
            "name":"Permission 2",
         }
      ]
   }
]

Solution

  • Got it with this:

    $role_permissions = Role::with('permissions')->get();
    

    (answered by questioner)