2021-07-13 02:31:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a ScopeActive to an Eloquent Model to only show active services (including those soon to be active)
|
|
|
|
*/
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
use App\Models\Service;
|
|
|
|
|
|
|
|
trait ScopeServiceActive
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Only query active service records
|
|
|
|
*/
|
|
|
|
public function scopeServiceActive($query)
|
|
|
|
{
|
2024-07-29 13:12:53 +00:00
|
|
|
return $query
|
|
|
|
->where(fn($q)=>
|
|
|
|
$q->where('services.active',TRUE)
|
|
|
|
->orWhere(fn($q)=>
|
|
|
|
$q->whereNotNull('order_status')
|
|
|
|
->whereNotIn('services.order_status',Service::INACTIVE_STATUS))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeServiceInactive($query)
|
|
|
|
{
|
|
|
|
return $query
|
|
|
|
->where(fn($q)=>
|
|
|
|
$q->where('services.active',FALSE)
|
|
|
|
->orWhere(fn($q)=>
|
|
|
|
$q->whereNotNull('order_status')
|
|
|
|
->whereIn('services.order_status',Service::INACTIVE_STATUS))
|
|
|
|
);
|
2021-07-13 02:31:56 +00:00
|
|
|
}
|
|
|
|
}
|