title: Laravel: how to set connection for many to many relationship?
body: <p>I have the models</p>
  
  <pre><code>class User extends Model
  {
      protected $connection = 'mysql';
  
      public function areas()
      {
          return $this-&gt;belongsToMany(Area::class, 'user_areas');
      }
  }
  
  
  class Area extends Model
  {    
      protected $connection = 'oracle';
  }
  </code></pre>
  
  <p>the user_areas table is searched on oracle, but this are on mysql.</p>
  
  <p>How I can indicate the connection for the pivot table?</p>
  
  <hr>
  
  <p>I found this partial solution and it has worked</p>
  
  <pre><code>class User extends Model
  {
      protected $connection = 'mysql'
  
      public function areas()
      {
          $instance = new Area;
          $instance-&gt;setConnection('mysql');
          return new BelongsToMany($instance-&gt;newQuery(), $this, 'user_areas', 'user_id', 'area_id', 'areas');
      }
  }
  </code></pre>