How to query pivot table where clause?

Posted 1 year ago by mchiasson

Hi everyone, I have 3 tables (users, departments, department_user), I can query the pivot table results fine on my returned views but I am trying to write an eloquent query with where clauses on the pivot table.

My pivot table has a column called "term_end_date" and I am trying to get all records prior to a certain date. Any suggestions on how I would do this?

$departments_past = Department::findOrFail($id)->where(pivot->term_end_date, <, '2017-10-10');

I'm sure I'm way off on this, could someone point me in the correct direction on how to query the results based on the pivot table data? Thanks!

Please sign in or create an account to participate in this conversation.