Home > Software engineering >  Laravel 8: Before editing a user I first want to check his role if he is an Admin I do a redirect::b
Laravel 8: Before editing a user I first want to check his role if he is an Admin I do a redirect::b

Time:03-01

enter image description here

En Laravel 8.

CodePudding user response:

The following may work for you

public function edit($id){
   // other codes and logics 

   if($userRole === 'Admin'){
       // let him edit
    }
   else {
         // redirect back
     }

Note : make sure $userRole is a string not array. if its a array specify its array index like $userRole[0] == 'Admin'

CodePudding user response:

Use \Auth::user()->role to get role type and then if else

public function edit($id){
   // other codes and logics 

   if(\Auth::user()->role === 'Admin'){
       // let him edit
    }
   else {
         // redirect back
     }
  • Related