title: Validating array in Laravel using custom rule with additional parameter
body: <p>I'm working with Laravel 5.7 and I need to validate a phone length by using 2 inputs (prefix+number). The total digits has to be 10 always.</p>
  
  <p>I'm using this custom rule for other projects which works fine:</p>
  
  <pre><code>&lt;?php
  namespace App\Rules;
  use Illuminate\Contracts\Validation\Rule;
  
  class PhoneLength implements Rule
  {
      public $prefix;
  
  /**
   * Create a new rule instance.
   *
   * @return void
   */
  public function __construct($prefix = null)
  {
      //
      $this-&gt;prefix = $prefix;
  }
  
  /**
   * Determine if the validation rule passes.
   *
   * @param  string  $attribute
   * @param  mixed  $value
   * @return bool
   */
  public function passes($attribute, $value)
  {
      //
      return strlen($this-&gt;prefix)+strlen($value) == 10 ? true : false;
  }
  
  /**
   * Get the validation error message.
   *
   * @return string
   */
  public function message()
  {
      return 'El Teléfono debe contener 10 dígitos (prefijo + número)';
  }
  }
  </code></pre>
  
  <p>In my controller I do something like </p>
  
  <pre><code>$validatedData = $request-&gt;validate([
    'prefix' =&gt; 'integer|required',
    'number' =&gt; ['integer','required', new PhoneLength($request-&gt;prefix)],
  ]);
  </code></pre>
  
  <p>Now I need to make use of arrays, so my new validation looks like</p>
  
  <pre><code>$validatedData = $request-&gt;validate([
    'phones.*.prefix' =&gt; 'required',
    'phones.*.number' =&gt; ['required', new PhoneLength('phones.*.prefix')],
  ]);
  </code></pre>
  
  <p>The above code doesn't work at all, the parameter is not being sent as expected.
  How can I send an array value? Of course I need to get the values from the same array element, so if <code>phones[0].number</code> is under validation, the prefix <code>phones[0].prefix</code> is needed.</p>
  
  <p>I've found this question, but I refuse to believe that is not possible to do in a "native" way:
  <a href="https://stackoverflow.com/questions/50348154/laravel-array-validation-with-custom-rule">Laravel array validation with custom rule</a></p>
  
  <p>Thanks in advance</p>