mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-19 17:19:22 +02:00
* refactor(api): prefer including pivot types to conditional pivot information * style: fix StyleCI findings
57 lines
1.3 KiB
PHP
57 lines
1.3 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;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
/**
|
|
* Class ImageLinkField.
|
|
*/
|
|
class ImageLinkField extends Field implements RenderableField
|
|
{
|
|
/**
|
|
* Create a new field instance.
|
|
*
|
|
* @param Schema $schema
|
|
*/
|
|
public function __construct(Schema $schema)
|
|
{
|
|
parent::__construct($schema, '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
|
|
{
|
|
$fs = Storage::disk(Config::get('image.disk'));
|
|
|
|
return $fs->url($model->getAttribute(Image::ATTRIBUTE_PATH));
|
|
}
|
|
}
|