Why does getAllPermissions()
with where condition (useing like
) isn't working in Laravel?
#2191
-
I am working in larael9 with spatie package to manage roles and permissions. I want to fetch user permissions with where condtion. my permissions table is as following
what i am trying to achieve is, get permissions were name start with 'admin_side_barmenu' for auth user I am able to get all the permissions but not able to get where it start with 'admin_side_barmenu'. I have tried the following way. Following is working for me if it fetchs with full name
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Because auth()->user()->getAllPermissions()
->filter( fn($p) => \Str::contains($p->name, 'admin_side_barmenu') )
->toArray(); |
Beta Was this translation helpful? Give feedback.
Because
getAllPermissions()
returns a collection, and collections don't uselike
, usefilter
with your own logic, like: