19 lines
529 B
PHP
19 lines
529 B
PHP
<?php
|
|
|
|
namespace App\Models\Concerns;
|
|
|
|
use App\Models\Organization;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
trait BelongsToOrganization
|
|
{
|
|
public function scopeForOrganization(Builder $query, Organization|int $organization): Builder
|
|
{
|
|
$organizationId = $organization instanceof Organization ? $organization->id : $organization;
|
|
|
|
return $query->whereHas('establishment', function (Builder $query) use ($organizationId) {
|
|
$query->where('organization_id', $organizationId);
|
|
});
|
|
}
|
|
}
|