How can I pass some variable in a custom validation rule from the controller validator?
For example:
class RegisterController extends Controller {
$someVariableINeed = 2
protected function validator(array $data) {
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'someField' => ['required', new \App\Rules\CustomValidationRule]
]);
}
.....
}
And the \App\Rules\CustomValidationRule :
.....
public function passes($attribute, $value) {
if ($value == 1 && $someVariableINeed == 2) {
return true
}
return false
}
.....
I need to pass variable $someVariableINeed from the RegisterController to the \App\Rules\CustomValidationRule.
Something similar to how max:255 works. I want to pass into my custom rule the 255.