0

I have a user database table that stores user roles. I need to validate if the user is either one of two roles in that table. Normally I could use exists but in this case, I need to check between two values.

How do I create a custom validation to do this? (I've an existing CustomValidator class)

E.g.

protected function validateUserRole($attribute, $value) {
    return (bool) ;
}

Columns in User role table:

id | user_id | role_id

Laravel rules:

$rules = array(
    'user_id' => ?
);

Thanks!

1
  • how do I put in multiple clauses? e.g. where role_id =1 or role_id=2? Commented Mar 22, 2015 at 11:16

1 Answer 1

0
ModelName::where('id', '=', 1)->orWhere('id', '=', 2)->first();

Take a look at the example above; should help you out :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I used my User model in the custom validation and it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.