intrip / laravel-authentication-acl

Laravel authentication and ACL admin panel package based on sentry
287 stars 110 forks source link

How can I get all permissions that user has including the permissions assigned to the group? #157

Closed elysiopires closed 7 years ago

elysiopires commented 7 years ago

How can I get all permissions that user has including the permissions assigned to the group?

Example Group 1 has:

User1 has: -Permission 4

I want to know if there is any method that returns all permissions?

Thx, Elysio

segsalerty2013 commented 7 years ago

@elysiopires Hope this helps

//get user id like this
$user_id = collect($request->session('sentry')->get(config('acl_sentry.cookie.key')))->first();
//then run query to get the user's group permission and permissions given to it outside the group
$what_you_need = DB::table('users_groups')->where('user_id', $user_id)
    ->leftJoin('groups', 'users_groups.group_id', '=', 'groups.id')
    ->leftJoin('users', 'users.id', '=', 'users_groups.user_id')
    ->select('groups.name', 'users_groups.user_id', 'groups.permissions', 'users.permissions')
    ->get();
dd($what_you_need);
elysiopires commented 7 years ago

Thank you! Works great! Have a nice day...