My application has Users and Groups. They are related with a pivot table. The pivot table has nullable "joined" and "left" datetimes.
How do I use Logical Grouping on a pivot table?
I've tried:
$this->belongsToMany(User::class)->wherePivot(function ($query) use ($time) {
$query->where('joined', null)->orWhere('joined', '<=', $time);
})
// and "left"
;
and
$this->belongsToMany(User::class)->where(function ($query) use ($time) {
$query->wherePivot('joined', null)->orWherePivot('joined', '<=', $time);
})
// and "left"
;
but neither work. The first complains about passing a function as an argument that's expected to be a string, and the second complains about wherePivot not being defined.
Am I missing something obvious?
if you are in the Group model you can define:
Or:
Then it can be called: