Support the ongoing development of Laravel.io →
Security Packages

Is there any function, facade or such to find out that a role contains a permission... something like


$role->can($permission_name);
// or
$role->has($permission_name);

or


$role->permissions()

that returns something like


output = array (
  [0] => 'permission_name_1',
  [1] => 'permission_name_2',
  [2] => 'permission_name_3',
  ...
)

to keep track of permissions synced with a role. Then it's possible to use array searches on them to.

Last updated 3 years ago.
0

HasRole has function

ability( $roles, $permissions, $options=array() )

Last updated 3 years ago.
0

Is this ability() function just available on a user? It doesn't seem to be available directly on a role

Last updated 3 years ago.
0

This should do the trick.

$role_permissions = $role->perms()->get();

@foreach($role_permissions as $rp) <p>{{$rp->display_name;}}</p> @endforeach

0

MelonSmasher said:

This should do the trick.

$role_permissions = $role->perms()->get();

@foreach($role_permissions as $rp) <p>{{$rp->display_name;}}</p> @endforeach

I like this,hope this works

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

MrAudioGuy mraudioguy Joined 23 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.