0

What I am trying to do is to get the length of an array inside closure Laravel validation.

Here is what I have tried:

        'attachment' => 'max:10',
        'attachment.*' => 'max:10240|mimes:jpeg,jpg,pdf',

        'deletedAttachments' => ['nullable', 'array', 'max:10', function($attribute, $value, $fail) {
            $fail(count($this->input('attachment')));
        }],

Unfortunately, This did not work and I am getting the following error:

Illuminate\Translation\PotentiallyTranslatedString::__toString(): Return value must be of type string, null returned

1
  • Where are you running this validation (controller, form request, etc ...)? And please explain what are you exactly trying to do. Commented Apr 4, 2024 at 1:49

1 Answer 1

1

as I remember, Laravel validation should give the data type first, maybe you could try:

[
'attachment' => 'array|max:10',
'attachment.*' => 'file|mimes:jpeg,jpg,pdf|max:10240',
//...other codes
]
Sign up to request clarification or add additional context in comments.

1 Comment

The issue was from the client side. Your answer is useful though. Thank you.

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.