$input = Input::only('account'); // dont use all(), ever
$rules = [
'account' => 'required'
];
if (filter_var($input['account'], FILTER_VALIDATE_EMAIL))
{
$rules['account'] .= '|exists:users,email';
}
else
{
$rules['account'] .= '|exists:users,username';
}
$validator = Validator::make($input, $rules);
You may want to consider adding your own rule which does the 'or' check in one rule. Maybe make it follow the exists
rule but takes in all column names. I'd guess it's relatively trivial to copy-and-paste the code for the current exists
rule and make it foreach
over a bunch of column names.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community