Laravel 5 - validate array as required, but allow an empty array to be passed Laravel 5 - validate array as required, but allow an empty array to be passed php php

Laravel 5 - validate array as required, but allow an empty array to be passed


Try this:

public function createSomeResource(Request $request){    $this->validate($request, [        'items' => 'present|array',    ];    ...}


Try:

public function createSomeResource(Request $request){    $this->validate($request, [        'items' => 'required|array|min:1',    ];    ...}

From Laravel doc:

min:value The field under validation must have a minimum value. Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.


1) Array is required

2) Value of all array is not null or empty

public static $rules = [   'category' => 'required|array|min:1',   'category.*' => 'required',];