osb/app/Traits/ScopeServiceActive.php
2022-04-20 12:43:10 +10:00

26 lines
537 B
PHP

<?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)
{
return $query->where(function($q) {
return $q->where('services.active',TRUE)
->orWhere(function($q) {
return $q->whereNotNull('order_status')
->whereNotIn('services.order_status',Service::INACTIVE_STATUS);
});
});
}
}