Added moduleIsEnabled scope to Model.php

This commit is contained in:
Cihan Şentürk 2025-04-27 16:24:29 +03:00 committed by GitHub
parent 4c25459dd7
commit 0fceb96078
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 0 deletions

View File

@ -246,6 +246,15 @@ abstract class Model extends Eloquent implements Ownable
return $query->where($this->qualifyColumn('type'), 'not like', '%-recurring');
}
public function scopeModuleEnabled(Builder $query, string $module): Builder
{
return $query->allCompanies()->whereHas('company', fn (Builder $q1) =>
$q1->enabled()->whereHas('modules', fn (Builder $q2) =>
$q2->allCompanies()->alias($module)->enabled(),
)
);
}
public function ownerKey($owner)
{
if ($this->isNotOwnable()) {