weird validation in nested array #53489
-
I tried some validation rule like: Boolean and Required file with nested array field, but always failing for example, I tried creating form request like this: <?php
namespace App\Http\Requests\Test;
use Illuminate\Foundation\Http\FormRequest;
class Test extends FormRequest
{
public function validationData()
{
return [
'booleanField' => $this->boolean("booleanField"),
'fileField' => $this->boolean("fileField"),
'arrayField' => $this->input("arrayField"),
'arrayField.*.booleanField' => $this->boolean("arrayField.*.booleanField"),
'arrayField.*.fileField' => $this->file("arrayField.*.fileField"),
];
}
public function rules(): array
{
return [
"booleanField" => ["required", "boolean"], // <= works as expected
"fileField" => ["required", "file", "mimes:jpg,png,jpeg,docx,xlsx,zip", "max:5120"], // <= works as expected
"arrayField" => ["required", "array"],
"arrayField.*.booleanField" => ["required", "boolean"], // <= not working, always returning error "The arrayField.0.booleanField field must be true or false."
"arrayField.*.fileField" => ["required", "file", "mimes:jpg,png,jpeg,docx,xlsx,zip", "max:5120"], // <= not working, always returning error "The arrayField.0.fileField is required."
];
}
} that's what I found. I don't know if any other rules also not working. Laravel version 11.31.0. |
Beta Was this translation helpful? Give feedback.
Answered by
bayukartiko
Nov 13, 2024
Replies: 1 comment
-
The base problem is from client request to my API that using answered at Stack Overflow |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
bayukartiko
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The base problem is from client request to my API that using
Content-Type: multipart/form-data
headeranswered at Stack Overflow