Hey everyone,
I've got a form that will have multiple email addresses and they should all be unique. I'm aware I have access to the "different" rule that comes with Laravel:
different:*field*
The field under validation must have a different value than *field*.
http://laravel.com/docs/5.1/validation#rule-different
My issue is that I'm unsure how I should write the rule for each email field using the different rule to apply to all the other email fields. My first guess is a double for loop? So let's say I have 8 email fields, all named sequentially email[1], email[2] etc, I'd do something like this:
for ($i = 1; $i < 8; $i++) {
for ($j = 1; $j < 8; $i++) {
if ($j !== $i) {
$rules['email.' . $i] .= '|different:email.' . $j;
}
}
}
So, if anyone could provide some guidance on the best way to do this I'd highly appreciate it.
Another issue I'm confused about is should I use the actual value of the input or can I simply reference the input name? So instead of:
$rules['email.' . $i] .= '|different:email.' . $j;
I would put:
$rules['email.' . $i] .= '|different:' . \Input::get('email.' . $j;