jeudi 16 août 2018

How to check multiple permission condition in if statement using laravel spatie package?

I need to check condition in if statement for multiple permissions. It is using spatie package from laravel. I use this code below but it seems doesn't work. It can display the output but the output is not correct. It doesn't filter the condition.

if (auth()->user()->can('View Consultant') || auth()->user()('View Administration') 
|| auth()->user()('View Accountant') || auth()->user()('All departments')) 
 {

        $itemregistrations = DB::table('itemregistrations')
                             ->where('categoryid','=', '1',',','2',',','3')
                             ->get();

        return view('profil.index', compact('itemregistrations'));

 } 

Is the code is correct?

The condition is the users with permission (view consultant, view administration, view accountant, all departments) can view list of consultant, administration and accountant from all departments.

For users with permission(view consultant only) can only view consultant list.

Aucun commentaire:

Enregistrer un commentaire