Answer
I was able to solve this using an additional package kirschbaum-development/eloquent-power-joins
I removed the scope from the Customer
model
ServiceCall model:
public function scopeNotContacted($builder)
{
$builder->joinRelationship('customers', function ($join) {
$join->where(function ($query) {
$query->whereNull('customers.last_contact_date')
->orWhereRaw('customers.last_contact_date < service_calls.next_service_date');
});
});
}
public function scopeUpcoming($builder)
{
$builder->whereBetween('next_service_date', [
Carbon::today(),
Carbon::today()->addDays(15)
])->notContacted();
}
0 comments:
Post a Comment
Thanks