mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-04 11:45:00 +02:00
37 lines
753 B
PHP
37 lines
753 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Api\Scope;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
class RelationScope extends Scope
|
|
{
|
|
public function __construct(protected readonly string $relation) {}
|
|
|
|
/**
|
|
* Get the relation of the scope.
|
|
*/
|
|
public function getRelation(): string
|
|
{
|
|
return $this->relation;
|
|
}
|
|
|
|
/**
|
|
* Get the type of the relation.
|
|
*/
|
|
public function getType(): string
|
|
{
|
|
return Str::of($this->getRelation())->explode('.')->last();
|
|
}
|
|
|
|
/**
|
|
* Determine if the provided scope is within this scope.
|
|
*/
|
|
public function isWithinScope(Scope $scope): bool
|
|
{
|
|
return $scope instanceof RelationScope && $this->relation === $scope->getRelation();
|
|
}
|
|
}
|