1

I have created the form and created multiple fields.

<input name="members[]" type="text" class="form-control">
<input name="members[]" type="text" class="form-control">
<input name="members[]" type="text" class="form-control">

set the validation from the Form Request for the input fields

public function rules()
{
    return [
        'password' => 'required|max:30',
        'members.*' => 'required|max:12',
    ];
}

How can we check the members' field value exists in the database using the validation? For password using like this

'password' => ['required', function ($attribute, $value, $fail) {
    if (!\Hash::check($value, $this->user()->password)) {
        $fail('Old Password did not match to our records.');
    }
}],
Moshiur
  • 659
  • 6
  • 22
Manmeet Khurana
  • 367
  • 2
  • 13

1 Answers1

1

You want to use the exists validation rule.

Just extend your existing validation rules for members:

'members.*' => 'required|max:12|exists:{phone number table},{phone nummber column}',
James
  • 15,754
  • 12
  • 73
  • 91