mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-28 23:26:55 +02:00
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Definition\Queries\Models;
|
|
|
|
use App\GraphQL\Definition\Fields\Base\DeletedAtField;
|
|
use App\GraphQL\Definition\Queries\BaseQuery;
|
|
use App\GraphQL\Definition\Types\EloquentType;
|
|
use Exception;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use RuntimeException;
|
|
|
|
abstract class EloquentQuery extends BaseQuery
|
|
{
|
|
/**
|
|
* Get the attributes of the type.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
...parent::attributes(),
|
|
|
|
'model' => $this->model(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the model related to the query.
|
|
*
|
|
* @return class-string<Model>
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function model(): string
|
|
{
|
|
$baseType = $this->baseRebingType();
|
|
|
|
if ($baseType instanceof EloquentType) {
|
|
return $baseType->model();
|
|
}
|
|
|
|
throw new RuntimeException('The base return rebing type must be an instance of EloquentType, '.get_class($baseType).' given.');
|
|
}
|
|
|
|
/**
|
|
* Determine if the return model is trashable.
|
|
*/
|
|
protected function isTrashable(): bool
|
|
{
|
|
$baseType = $this->baseRebingType();
|
|
|
|
if ($baseType instanceof EloquentType) {
|
|
return in_array(new DeletedAtField(), $baseType->fieldClasses());
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Manage the query.
|
|
*/
|
|
protected function query(Builder $builder, array $args): Builder
|
|
{
|
|
return $builder;
|
|
}
|
|
}
|