Laravel-permission: Permissions table is not returning data

Created on 3 May 2019  路  4Comments  路  Source: spatie/laravel-permission

Hey, Hope you're doing well.

I tried many times to retrieve all the records of the permissions table by using the query builder and eloquent. But in both cases, the permission table returns an empty array.

I wanna display roles as shown in the snapshot.
image

So, how I can retrieve the records?

Most helpful comment

There is no magic involved here, Permission::all() should (and does for me) work perfectly fine.

All 4 comments

There is no magic involved here, Permission::all() should (and does for me) work perfectly fine.

Yes, Permission::all() will return all the permission records.

@drbyte I get empty array if I write this:
auth()->user()->getPermissionNames()
But if I write this, i get collection of permissions:
auth()->user()->getAllPermissions()

why it is not returning permission names only?

@drbyte I get empty array if I write this:
auth()->user()->getPermissionNames()
But if I write this, i get collection of permissions:
auth()->user()->getAllPermissions()

why it is not returning permission names only?

getPermissionNames() only returns direct permissions assigned to the user, not those inherited by associated roles.
However, getAllPermissions() goes and inspects the roles as well. So you could get the names from that by using getAllPermissions()->pluck('name');

Was this page helpful?
0 / 5 - 0 ratings