Support the ongoing development of Laravel.io →
posted 10 years ago
Validation
Last updated 2 years ago.
0
$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);
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Almis90 almis90 Joined 25 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.