Skip to content
Advertisement

Make eloquent query filtered by a result of this query

I try to get events from my database

JavaScript

I would like to filter my relationship persons.health_items.

The ideal would be to have something like that :

JavaScript

$eventWithDatas should be the first part of my query (Event::get)

Example with result:

JavaScript

Do you know how I can do this?

Advertisement

Answer

The key to your constrained eager loading approach is to join to the events table, so we can compare the date_end and end fields. Assuming you have many-to-many persons to events, you can do this as follows:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement