QuestionablePlop
QuestionablePlop

Reputation: 13

check a user_role laravel 5.4

What would be the best way to add a custom validation of checking if a user has a certain role. using a roles table and role_user pivot table

the roles table has 3 roles

1 user 2 mentor 3 admin

protected function validateLogin(Request $request)
{
    $this->validate($request, [
        $this->username() => [
        'required','string',
        Rule::exists('users')->where(function ($query){
            $query->where('active', true);
            }),
        ], 

        'password' => 'required|string',
       ], $this->validation_errors());

 }

Upvotes: 0

Views: 262

Answers (1)

Check out the middleware documentation: Laravel - Middlewares

You should create a middleware that checks if the user has the role you want and add it to your route.

Upvotes: 1

Related Questions