How to use wherePivot() inside whereHas() in a query ?
Hello,
I have to filter some data via a specific pivot table column.
$events = Event::query()
->whereHas('teams', function ($query) use ($user) {
$query->whereHas('users', function ($query) {
$query->wherePivot() // here the pivot table is team_user and I need to check a column from the pivot table
});
})
->orWhereDoesntHave('teams')
->get();
It doesn't work, I think that wherePivot is only for the declaration of a relationship. Is it possible to use it inside a query ? Or perhaps an equivalent function for a query ?
Furthermore the condition is that the created_at date from the pivot table has to be inferior than the creation date of the event.
@tisuchi That's pretty interesting, I never used DB::raw() inside a where() close like this. It should work, I will try this tomorrow and I tell you if it's ok.