Files
animethemes-server/app/Http/Api/Field/Wiki/Audio/AudioLinkField.php
T
paranarimasu 295a997354 Api allowed pivots (#570)
* refactor(api): prefer including pivot types to conditional pivot information

* style: fix StyleCI findings
2023-04-14 18:36:29 -05:00

52 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Api\Field\Wiki\Audio;
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 Illuminate\Database\Eloquent\Model;
/**
* Class AudioLinkField.
*/
class AudioLinkField 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
{
return route('audio.show', $model);
}
}