How to validate whole request is an array in Laravel?

Viewed 187

I need to validate the JSON body of a request, and it must be an array.

I know I can validate individual fields as an array like so:

$request->validate([
    'name' => ['required', 'array'],
]);

but how can I validate that the whole request is an array instead of, say, an object?

1 Answers

You can use Middleware to check raw request body. request()->all() will always return array.

Related