title: Laravel validate array of object JSON
body: <p>I have a POST endpoint on my Laravel 5.5 API, I used postman to test my route and here is the problem.
  I want to send an array of the same kind of object, like this:</p>
  <pre><code>[
    { 
     &quot;name&quot;:&quot;test&quot;,
     &quot;tag&quot;:&quot;TEST&quot;
    },
    {
     &quot;name&quot;:&quot;test2&quot;,
     &quot;tag&quot;:&quot;TEST_2&quot;
    }
  ]
  </code></pre>
  <p>But I can't manage to validate it properly.</p>
  <p>in my controller, I have this:</p>
  <pre><code>$validator = Validator::make($requests-&gt;all(), [
   
     'name' =&gt; 'required|string',
     'tag' =&gt; 'required|string'
  ]);
  
  if($validator-&gt;fails()) 
     //Warn user for errors 
  </code></pre>
  <p>I also tried with the simple</p>
  <pre><code>$this-&gt;validate($requests-&gt;all() .... )
  </code></pre>
  <p>I tried renaming the rules with <code>'.name'</code> and <code>'*.name'</code> but no success.</p>
  <p>I tried replacing <code>$request-&gt;all()</code> with <code>$request-&gt;input()</code>but no success.</p>
  <p>I also tried to loop over it but I get exceptions</p>
  <pre><code>foreach($request as $req){
  
    $validator = Validator::make($req ....) 
  
    //rest of the code
  }
  </code></pre>
  <p>On the other hand, I can retrieve the data like this <code>$datas = $request-&gt;all()</code> and store them but there is no validation.</p>
  <p>The only solution that seems to be working is naming my array:</p>
  <pre><code>{
   &quot;data&quot; : [
        { 
         &quot;name&quot;:&quot;test&quot;,
         &quot;tag&quot;:&quot;TEST&quot;
        },
        {
         &quot;name&quot;:&quot;test2&quot;,
         &quot;tag&quot;:&quot;TEST_2&quot;
        }
      ]
  }
  </code></pre>
  <p>And then name the rules with <code>'data.*.name'</code> but this obliges the API user to parse the array.
  Let suppose I have an array <code>$array</code> which I want to store, I need to do</p>
  <pre><code>$arrayParsed = ['data' =&gt; $array]
  </code></pre>
  <p>and call the API with <code>$arrayParsed</code>, which I think is a little redundant.</p>
  <p>Is there a better way to handle the problem?</p>