Files
animethemes-server/app/Http/Api/Field/Wiki/Image/ImageLinkField.php
T
2024-12-08 19:53:24 -03:00

53 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Api\Field\Wiki\Image;
use App\Contracts\Http\Api\Field\RenderableField;
use App\Http\Api\Field\Field;
use App\Http\Api\Query\Query;
use App\Http\Api\Schema\Schema;
use App\Models\Wiki\Image;
use Illuminate\Database\Eloquent\Model;
/**
* Class ImageLinkField.
*/
class ImageLinkField extends Field implements RenderableField
{
/**
* Create a new field instance.
*
* @param Schema $schema
*/
public function __construct(Schema $schema)
{
parent::__construct($schema, Image::ATTRIBUTE_LINK);
}
/**
* Determine if the field should be displayed to the user.
*
* @param Query $query
* @return bool
*/
public function shouldRender(Query $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 $model->getAttribute($this->getColumn());
}
}