title: How to pass the value of an item in an array to the validation rule of another parameter in Laravel?
body: <pre><code>$validator = Validator::make($data, [
          'business_hours' =&gt; ['string','max:100','regex:/([0-7]:([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9],?)?/'],
          'industries' =&gt; 'array',
          'industries.*.industry' =&gt; 'numeric',
          'industries.*.license' =&gt; 'array',
          'industries.*.license.*' =&gt; 'numeric|exists:industry_license,license_id,industry_id',
      ]);
  </code></pre>
  <p>In the validation rule above I would want to validate that the value in <code>&quot;industries.*.industry&quot;</code> and <code>'industries.*.license.*'</code> is being validated such that in the <code>exists</code> rule in <code>&quot;industries.*.license.*&quot;</code>, both the industry value and license value are being validated.</p>
  <p>This is the migration script for the industry_license table.</p>
  <pre><code>Schema::create('industry_license', function (Blueprint $table) {
          $table-&gt;unsignedInteger('license_id');
          $table-&gt;unsignedInteger('industry_id');
  
          $table-&gt;primary(['license_id', 'industry_id']);
      });
  </code></pre>
  <p>This is the sample body of the request:</p>
  <pre><code>&quot;business_hours&quot;: &quot;2:10:00:14:00,3:0:00:23:00,4:0:00:23:00,5:0:00:23:00,6:0:00:23:00,7:0:00:23:00,1:0:00:23:00&quot;,
  &quot;industries&quot;: [
      {
          &quot;industry&quot; : 3,
          &quot;license&quot;: [2,4,7]
      },
      {
          &quot;industry&quot; : 2,
          &quot;license&quot;: [3]
      }
  ]
  </code></pre>
  <ol>
  <li><p>In short I just want to validate that the pair <code>industry_id</code> and <code>license_id</code> exists in the <code>industry_license</code> table.</p>
  </li>
  <li><p>Also, what regex value do I use to validate this string in the <code>business_hours</code> field:</p>
  <p>&quot;2:10:00:14:00,3:0:00:23:00,4:0:00:23:00,5:0:00:23:00,6:0:00:23:00,7:0:00:23:00,1:0:00:23:00&quot;</p>
  </li>
  </ol>
  <p>The expected value in the <code>business_hours</code> field is <code>{day}:{start_time}:{end_time}</code>, ex. <code>(2:10:00:14:00)</code> which would translate to Tuesday 10am - 2pm. Basically it's a comma delimited string of scheduled dates.</p>