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.');
    }
}],
6
  • 1
    What is the value of the input and what does it map to in your database? Commented Mar 19, 2020 at 4:44
  • yes it maps with the database and field name is member Commented Mar 19, 2020 at 4:46
  • That is not what I asked, is it an integer, is it a piece of text. What is the value and which table and column does is map to? Commented Mar 19, 2020 at 4:48
  • Does this answer your question? How to validate array in Laravel? Commented Mar 19, 2020 at 4:49
  • @DhavalNaphade I want to check field value from database and want to set the query example its autocomplete field with phone number and want to check phone number exist in database or not Commented Mar 19, 2020 at 4:52

1 Answer 1

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}',
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.