Files
animethemes-server/app/Http/Api/Field/Wiki/Video/Script/ScriptLinkField.php
T
paranarimasu 0fc9fd832c refactor(api): mark fields as renderable for display to the user with custom logic [incremental] (#513)
* refactor(api): mark fields as renderable for display to the user with custom logic

* style: fix StyleCI findings
2023-02-04 23:52:01 -06:00

53 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Api\Field\Wiki\Video\Script;
use App\Contracts\Http\Api\Field\RenderableField;
use App\Http\Api\Field\Field;
use App\Http\Api\Query\ReadQuery;
use App\Http\Api\Schema\Schema;
use App\Http\Resources\Wiki\Video\Resource\ScriptResource;
use Illuminate\Database\Eloquent\Model;
/**
* Class ScriptLinkField.
*/
class ScriptLinkField extends Field implements RenderableField
{
/**
* Create a new field instance.
*
* @param Schema $schema
*/
public function __construct(Schema $schema)
{
parent::__construct($schema, ScriptResource::ATTRIBUTE_LINK);
}
/**
* Determine if the field should be displayed to the user.
*
* @param ReadQuery $query
* @return bool
*/
public function shouldRender(ReadQuery $query): bool
{
$criteria = $query->getFieldCriteria($this->schema->type());
return $criteria === null || $criteria->isAllowedField($this->getKey());
}
/**
* Get the value to display to the user.
*
* @param Model $model
* @return string
*/
public function render(Model $model): string
{
return route('videoscript.show', $model);
}
}