mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 16:24:03 +00:00
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.
35 lines
822 B
PHP
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);
|
|
});
|
|
}
|
|
}
|