mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-31 03:33:21 +01:00
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Api\Field\Document\Page;
|
|
|
|
use App\Contracts\Http\Api\Field\CreatableField;
|
|
use App\Contracts\Http\Api\Field\RenderableField;
|
|
use App\Contracts\Http\Api\Field\SelectableField;
|
|
use App\Contracts\Http\Api\Field\UpdatableField;
|
|
use App\Http\Api\Criteria\Field\Criteria;
|
|
use App\Http\Api\Field\Field;
|
|
use App\Http\Api\Query\Query;
|
|
use App\Http\Api\Schema\Schema;
|
|
use App\Models\Document\Page;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PageBodyField extends Field implements CreatableField, RenderableField, SelectableField, UpdatableField
|
|
{
|
|
public function __construct(Schema $schema)
|
|
{
|
|
parent::__construct($schema, Page::ATTRIBUTE_BODY);
|
|
}
|
|
|
|
public function getCreationRules(Request $request): array
|
|
{
|
|
return [
|
|
'required',
|
|
'string',
|
|
'max:16777215',
|
|
];
|
|
}
|
|
|
|
public function shouldRender(Query $query): bool
|
|
{
|
|
$criteria = $query->getFieldCriteria($this->schema->type());
|
|
|
|
return $criteria instanceof Criteria && $criteria->isAllowedField($this->getKey());
|
|
}
|
|
|
|
public function render(Model $model): mixed
|
|
{
|
|
return $model->getAttribute($this->getColumn());
|
|
}
|
|
|
|
public function shouldSelect(Query $query, Schema $schema): bool
|
|
{
|
|
$criteria = $query->getFieldCriteria($this->schema->type());
|
|
|
|
return $criteria instanceof Criteria && $criteria->isAllowedField($this->getKey());
|
|
}
|
|
|
|
public function getUpdateRules(Request $request): array
|
|
{
|
|
return [
|
|
'sometimes',
|
|
'required',
|
|
'string',
|
|
'max:16777215',
|
|
];
|
|
}
|
|
}
|