1

I have fields with array field names and I am having issues validating the fields. An example is: user[first_name]

$this->validate(request(), [
    'user[first_name]' => 'required|min:15',
]);

if ($errors->any()) {
  print_r($errors->all());exit;
}

It seems that Laravel does not detect the field this way, I get user[first_name] is required.

Help will be appreciated.

2 Answers 2

2

replace user[first_name] with user.first_name

$this->validate(request(), [
    'user.first_name' => 'required|min:15',
]);
Sign up to request clarification or add additional context in comments.

Comments

1

You should try to retrieve the user object from the request, e.g.:

$this->validate(request('user'), [
    'first_name' => 'required|min:15',
]);

Or even better using dot notation:

$this->validate(request(), [
    'user.first_name' => 'required|min:15',
]);

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.