title: Eloquent query based on presence of key in relationship group
body: <p>So this one has kinda given me a mental run around. I have <code>Row</code>s, <code>User</code>s, and <code>RowActivity</code> models. Each time a user interacts with a row, it generates a single line in the row activity table saying what status the user changed. Each row can have 3-8 activity entries with a single user reference per line. So my question is this: I want to analyze the rows that particular users have interacted with. So I'd like to search for user A and get all the rows they've touched. But the only way to do that is to query the <code>RowActivity</code> table.</p>
  <p>So the query would essentially be this:</p>
  <p><code>Row::whereHas('rowActivity')-&gt;whereWithin(Collection of RowActivity, user_id = requested-user)-&gt;get();</code></p>
  <p>I know that I can go the long way and query the <code>RowActivity::where('user_id', $requestedUser)</code> and then get all the other row activities based on the related <code>row_id</code> of that those results, but I feel there's a clean way that I can't figure out.</p>
  <p>Just for clarification, the row activities are used to generate reports about which users changed the status of the row and how long the duration between the changes are. So I need to get all the activities associated with a row as well as all the rows that a user has touched so that I can analyze how long their portion of that interaction took.</p>
  <p>If I need to do this as a multilevel query, so be it, I don't have an aversion to that, I just want to make sure my queries are pristine. If I did it as multi-level, it would look something like this:</p>
  <pre><code>$ra = RowActivity::where('user_id', $requestedUser)-&gt;pluck('row_id');
  $rows = Row::with('rowActivity')-&gt;find($ra); //get all rows and their associated activities based on the plucked row id from query 1
  </code></pre>