title: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias on relationship
body: <p>So, I'm receiving the following error from Laravel framework; but I couldn't find why this framework is producing this error:</p>
  
  <pre><code>SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'participants' (SQL: select `participants`.*, `participants`.`message_id` as `pivot_message_id`, `participants`.`user_id` as `pivot_user_id`, `participants`.`created_at` as `pivot_created_at`, `participants`.`updated_at` as `pivot_updated_at` from `participants` inner join `participants` on `participants`.`id` = `participants`.`user_id` where `participants`.`deleted_at` is null and `participants`.`message_id` in (2))
  </code></pre>
  
  <p>My message/participants relationship looks like this: </p>
  
  <pre class="lang-php prettyprint-override"><code>public function participants()
  {
      return $this-&gt;belongsToMany('Namespace\Modules\Email\Models\Participant', 'participants', 'message_id', 'user_id')-&gt;withTimestamps();
  }
  </code></pre>
  
  <p>and I'm trying to call it like this: </p>
  
  <pre class="lang-php prettyprint-override"><code>public function getAllMessages()
  {
     return Message::with('user')-&gt;with('participants')-&gt;get();
  }
  </code></pre>
  
  <p>Why am I getting this error? What's going on? </p>
  
  <p><strong>Edit: Included full models</strong></p>
  
  <p><strong><em>Message</em></strong></p>
  
  <pre class="lang-php prettyprint-override"><code>class Message extends Eloquent
  {
      use PublishedTrait;
      use SoftDeletingTrait;
  
      /**
       * The database table used by the model.
       *
       * @var string
       */
      protected $table = 'messages';
  
      /**
       * The attributes that can be set with Mass Assignment.
       *
       * @var array
       */
      protected $fillable = ['subject', 'user_id', 'body', 'status'];
  
      /**
       * The attributes that should be mutated to dates.
       *
       * @var array
       */
      protected $dates = ['created_at', 'updated_at', 'deleted_at'];
  
      /**
       * Validation rules.
       *
       * @var array
       */
      protected $rules = [
          'subject' =&gt; 'required|max:255',
          'body' =&gt; 'required',
      ];
  
      /**
       * User relationship
       *
       * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
       */
      public function user()
      {
          return $this-&gt;belongsTo(Config::get('email.user_model'));
      }
  
      public function assets()
      {
          return $this-&gt;belongsToMany('Namespace\Modules\Assets\Models\Asset', 'message_assets');
      }
  
      /**
       * Participants relationship
       *
       * @return \Illuminate\Database\Eloquent\Relations\HasMany
       */
      public function participants()
      {
          return $this-&gt;belongsToMany('Namespace\Modules\Email\Models\Participant', 'participants', 'message_id', 'user_id')-&gt;withTimestamps();
      }
  
      /**
       * Recipients of this message
       *
       * @return \Illuminate\Database\Eloquent\Relations\HasMany
       */
      public function recipients()
      {
          return $this-&gt;participants()-&gt;where('user_id', '!=', $this-&gt;user_id);
      }
  
      /**
       * Returns the latest message from a thread
       *
       * @return Namespace\Modules\Email\Models\Message
       */
      public function getLatestMessageAttribute()
      {
          return $this-&gt;messages()-&gt;latest()-&gt;first();
      }
  
      /**
       * Returns threads that the user is associated with
       * @param $query
       * @param $userId
       * @return mixed
       */
      public function scopeForUser($query, $userId)
      {
          return $query-&gt;join('participants', 'messages.id', '=', 'participants.message_id')
              -&gt;where('participants.user_id', $userId)
              -&gt;where('participants.deleted_at', null)
              -&gt;select('messages.*');
      }
  
      /**
       * Returns threads that the user is associated with
       * @param $query
       * @param $userId
       * @return mixed
       */
      public function scopeForUserWithDeleted($query, $userId)
      {
          return $query-&gt;join('participants', 'messages.id', '=', 'participants.message_id')
              -&gt;where('participants.user_id', $userId)
              -&gt;select('messages.*');
      }
  
      /**
       * Returns messages that the user has sent
       * @param $query
       * @param $userId
       * @return mixed
       */
      public function scopeByUser($query, $userId)
      {
          return $query-&gt;where('user_id', $userId);
      }
  
      /**
       * Returns threads with new messages that the user is associated with
       * @param $query
       * @param $userId
       * @return mixed
       */
      public function scopeForUserWithNewMessages($query, $userId)
      {
          return $query-&gt;join('participants', 'messages.id', '=', 'participants.message_id')
              -&gt;where('participants.user_id', $userId)
              -&gt;whereNull('participants.deleted_at')
              -&gt;where(function ($query) {
                  $query-&gt;where('messages.updated_at', '&gt;', $this-&gt;getConnection()-&gt;raw($this-&gt;getConnection()-&gt;getTablePrefix() . 'participants.last_read'))
                      -&gt;orWhereNull('participants.last_read');
              })
              -&gt;select('messages.*');
      }
  
  }
  </code></pre>
  
  <p><strong><em>Participant</em></strong></p>
  
  <pre class="lang-php prettyprint-override"><code>class Participant extends Eloquent
  {
      use SoftDeletingTrait;
  
      /**
       * The database table used by the model.
       *
       * @var string
       */
      protected $table = 'participants';
  
      /**
       * The attributes that can be set with Mass Assignment.
       *
       * @var array
       */
      protected $fillable = ['message_id', 'user_id', 'last_read'];
  
      /**
       * The attributes that should be mutated to dates.
       *
       * @var array
       */
      protected $dates = ['created_at', 'updated_at', 'deleted_at', 'last_read'];
  
      /**
       * Thread relationship
       *
       * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
       */
      public function message()
      {
          return $this-&gt;hasMany('Namespace\Modules\Email\Models\Message');
      }
  
      /**
       * User relationship
       *
       * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
       */
      public function user()
      {
          return $this-&gt;belongsTo(Config::get('email.user_model'));
      }
  }
  </code></pre>