title: Custom validation rule checking existence with column name and filter
body: <p>I want to validate that the user has selected a valid state value in an address form. For simplicity while developing, I'm not letting them pick the country yet.</p>
  
  <p>The state information is in a table with the following fields:</p>
  
  <pre><code>id
  country_id
  abbreviation
  name
  </code></pre>
  
  <p>The form uses a select element with name <code>address[state]</code> and sends the state ID as the selected value.</p>
  
  <p>My first try at the validation rule was:</p>
  
  <pre><code>'address.state' =&gt; [
      'required',
      Rule::exists('shop_address_states')-&gt;where(function ($query) {
          $query-&gt;where('country_id', 1);
      }),
  ],
  </code></pre>
  
  <p>But I get an <code>Unknown column 'address.state'</code> error.</p>
  
  <p>When I try to get it to use the ID column instead:</p>
  
  <pre><code>'address.state' =&gt; [
      'required',
      Rule::exists('shop_address_states,id')-&gt;where(function ($query) {
          $query-&gt;where('country_id', 1);
      }),
  ],
  </code></pre>
  
  <p>I get an <code>undefined offset: 1</code> error.</p>
  
  <p>I guess I'm kind of mashing the rule <code>'state' =&gt; 'exists:states,abbreviation'</code> from <a href="https://laravel.com/docs/5.4/validation#rule-exists" rel="nofollow noreferrer">https://laravel.com/docs/5.4/validation#rule-exists</a> since I haven't been able to find an example elsewhere.</p>
  
  <p>How do I get this rule to work?</p>