title: Laravel Three-way Many-to-Many Eloquent Relationship
body: <p>I have database like this<br>
  <code>accounts</code> </p>
  
  <ul>
  <li>id   </li>
  <li>name  </li>
  </ul>
  
  <p><code>contacts</code><br>
   - id<br>
   - account_id<br>
  <code>account_communications</code><br>
   - id<br>
   - account_id</p>
  
  <p>and contact model :  </p>
  
  <pre><code>class Contact extends Model
  { 
      public function Account()
      {
         return $this-&gt;belongsTo('App\Account');
      }
     public function AccountCommunication()
     {
        return $this-&gt;hasManyThrough( 'App\AccountCommunication','App\Account');
     }
  }
  </code></pre>
  
  <p>Account model</p>
  
  <pre><code> class Account extends Model
   {
       public function AccountCommunication()
        {
            return $this-&gt;hasMany('App\AccountCommunication');
        } 
      public function Contact()
      {
          return $this-&gt;hasMany('App\Contact');
       }
   }
  </code></pre>
  
  <p>AccountCommunication model</p>
  
  <pre><code>class AccountCommunication extends Model
   {
        public function Account()
       {
            return $this-&gt;belongsToMany('App\Account');
        }
    }
  </code></pre>
  
  <p>On my controller</p>
  
  <pre><code>class ContactController extends Controller
    {
       public function index()
       {
          $contacts = Contact::with('Account')-&gt;with('AccountCommunication')-&gt;paginate(10);
        dd($contacts);
       }
    }
  </code></pre>
  
  <p>Show me this error</p>
  
  <blockquote>
    <p>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts.contact_id' in 'field list' (SQL: select <code>account_communications</code>.*, <code>accounts</code>.<code>contact_id</code> from <code>account_communications</code> inner join <code>accounts</code> on <code>accounts</code>.<code>id</code> = <code>account_communications</code>.<code>account_id</code> where <code>accounts</code>.<code>contact_id</code> in (20))</p>
  </blockquote>