title: Laravel request validation with custom tenant connection on-the-fly
body: <p>I'm creating an SaaS application with multiple databases and the connection to the database is set on-the-fly according to the user logged in. <a href="https://stackoverflow.com/questions/55908755/laravel-one-domain-multiple-database-detected-by-session">You can see my problem and solution here</a> back when I was trying to figure out how to do it.</p>
  
  <p>My problem now is using the <code>$request-&gt;validate</code> function with both <code>unique</code> and <code>exists</code> functions.</p>
  
  <p>The documentation says that we can set a Custom Database Connection, by doing something like:</p>
  
  <pre><code>'email' =&gt; 'unique:connection.clients,email'
  </code></pre>
  
  <p>But this forces me to create my connections within the <code>config\database.php</code> file and that's something I don't want to do.</p>
  
  <p>Currently, if I do:</p>
  
  <pre><code>$request-&gt;validate(['email' =&gt; 'required|unique:clients,email']);
  </code></pre>
  
  <p>I got an error saying: </p>
  
  <blockquote>
    <p>Base table or view not found: 1146 Table
    'mydb_admin.clients'</p>
  </blockquote>
  
  <p>Which is correct, since my Admin database does not have the table <code>clients</code>. So how can I, with the system I have in place, use the <code>$request-&gt;validate</code> function with my child databases?</p>