Laravel Many To Many Method Issue
<p>I have a many to many relationship between the models User &amp; Notification.</p>

<p>User Model:</p>

<pre><code>public function notifications()
{
    return $this-&gt;belongsToMany('Yeayurdev\Models\Notification', 'notifications_user', 'user_id', 'notification_id')
        -&gt;withPivot('notifier');
}
</code></pre>

<p>Notification Model:</p>

<pre><code>public function user()
{
    return $this-&gt;belongsToMany('Yeayurdev\Models\User', 'notifications_user', 'notification_id', 'user_id');
}
</code></pre>

<p>Pivot Table:</p>

<pre><code>ID     USER_ID     NOTIFICATION_ID
1         2               1
</code></pre>

<p>In my view, I retrieve a list of all notifications for a user like so.</p>

<pre><code>@foreach (Auth::user()-&gt;notifications as $notification)
   {{ $notification-&gt;user-&gt;username }}
@endforeach
</code></pre>

<p>The problem is that when I try to get the username of the user with that notifications, I get the error Undefined property: Illuminate\Database\Eloquent\Collection::$username. "Username" is the column on my users table which is just a string. I don't see where I'm going wrong because if I just do "$notificatin->user" it gives me the collection.</p>

<p>Thanks!</p>