title: Laravel: How to get single pivot row by key id
body: <p>I have a many-to-many relation set on my <strong>User</strong> and <strong>Notification</strong> Eloquent models. This way I can access the pivot table - <strong>user_notifications</strong> - as follows:</p>
  
  <pre><code>$user = User::find(1);
  foreach ($user-&gt;notifications() as $n) {
      echo $n-&gt;pivot-&gt;created_at;
  }
  </code></pre>
  
  <p>This will give me all <code>created_at</code> field values from the pivot table, for the user of ID = 1.</p>
  
  <p>What if I need <strong>only one</strong> pivot row, let's say the one with <strong>notification_id = 2</strong>? Is there a way to combine <code>pivot</code> with <code>where</code> or <code>has</code>? Can it be done without looping through <code>$user-&gt;notifications()</code>?</p>