murilo
1 year ago

Auth credential with Roles

Posted 1 year ago by murilo

Hello Guys , does some one can help me ? I am making a verification Guard for AdminUsers and CoustomerUsers , like this -

https://laracasts.com/lessons/users-and-roles

I have my table USER -

    id | name | email |password
        1 | John | [email protected] |12345

I have my table USER_ROLE -

    id | name_of_role 
       1  | admin

I have my table USER_ROLE_USER , ( MANY TO MANY RELATION SHIP)

    user_id | role_user_id 
        1 | 1

I changed the file -RedirectIfAuthenticated and Added those guards .

It is working and redirecting how is loged in with roles .

BUT I have to change this credentials that verificate in my Authentication Login on Laravel , it is like this -

  $credentials = ['email' => $request['email'] , 'password' => $request['password'] ;

        if(auth()->guard()->attempt($credentials)){
        ....
    }

I should verificate the role as well in the credentials , something like this -

  $credentials = ['email' => $request['email'] , 'password' => $request['password'] ,  'role' => ?  ;

        if(auth()->guard()->attempt($credentials) ){
        ....
    }

Thanks

Please sign in or create an account to participate in this conversation.