1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 16:24:03 +00:00
tenancy/src/Database/ParentModelScope.php
Samuel Stancl c32f52ce7c
phpstan fix: Scope generics
phpstan started failing with '... implements generic interface
Illuminate\Database\Eloquent\Scope but does not specify its types:
TModel'. We solve this by adding an implements docblock to the scopes
implementing that interface. They're fairly generic - we just use the
Model type itself in the code - so we use Model for the type parameter.
2026-04-15 11:23:12 +02:00

35 lines
822 B
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
/** @implements Scope<Model> */
class ParentModelScope implements Scope
{
/**
* @param Builder<Model> $builder
*/
public function apply(Builder $builder, Model $model): void
{
if (! tenancy()->initialized) {
return;
}
$builder->whereHas($builder->getModel()->getRelationshipToPrimaryModel());
}
/**
* @param Builder<Model> $builder
*/
public function extend(Builder $builder): void
{
$builder->macro('withoutParentModel', function (Builder $builder) {
return $builder->withoutGlobalScope(static::class);
});
}
}