title: Laravel Many to Many Relationship 5 tables
body: <p>I have a model called Members, another called Awards and another called Events.</p>
  
  <p>Each member can have multiple awards more than once and each award can be assigned to multiple members, these can be awarded on the members profile or as a result of an event.</p>
  
  <p><strong>My member model relationship:</strong></p>
  
  <pre><code>public function Awards()
      {
          return $this-&gt;belongsToMany('App\Award', 'award_members', 'member_id', 'award_id')
                      -&gt;withTimestamps()
                      -&gt;orderBy('award_members.created_at','desc');
      }
  </code></pre>
  
  <p><strong>My relations table:</strong></p>
  
  <pre><code>Schema::create('award_members', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;integer('user_id');
              $table-&gt;integer('club_id');
              $table-&gt;integer('award_id');
              $table-&gt;integer('member_id');
              $table-&gt;integer('event_id')-&gt;nullable();
              $table-&gt;timestamps();
          });
  </code></pre>
  
  <p><strong>My view output:</strong></p>
  
  <pre><code>@foreach($member-&gt;Awards as $a)
    {{ $a-&gt;title }} | {{ $a-&gt;pivot-&gt;created_at }}
  @endforeach
  </code></pre>
  
  <p><strong>This outputs:</strong></p>
  
  <ul>
  <li>Award 1 | 12/08/2016  </li>
  <li>Award 2 | 12/08/2016</li>
  <li>Award 1 | 11/08/2016</li>
  </ul>
  
  <p>I'd also like to output if stored in the relations table the event name if it was added to the members profile via an event. the above only shows details of awards when added directly to the member.</p>
  
  <p><strong>In my relations table an entry from an event would look similar to:</strong></p>
  
  <ul>
  <li>id = 4 </li>
  <li>user_id = 1 (related to user table)</li>
  <li>club_id = 1 (related to club table)</li>
  <li>award_id = 3 (related to awards table)</li>
  <li>member_id = 1 (related to members table)</li>
  <li>event_id = 1 (related to events table but can be NULL)</li>
  </ul>
  
  <p>How can I output when entered the event name?</p>