mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-20 01:29:24 +02:00
* refactor(api): prefer composition to strict inheritance for API queries, requests & actions * style: fix StyleCI findigns
59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Api\Field\Wiki\Audio;
|
|
|
|
use App\Contracts\Http\Api\Field\CreatableField;
|
|
use App\Http\Api\Field\StringField;
|
|
use App\Http\Api\Query\Query;
|
|
use App\Http\Api\Schema\Schema;
|
|
use App\Models\Wiki\Audio;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Class AudioBasenameField.
|
|
*/
|
|
class AudioBasenameField extends StringField implements CreatableField
|
|
{
|
|
/**
|
|
* Create a new field instance.
|
|
*
|
|
* @param Schema $schema
|
|
*/
|
|
public function __construct(Schema $schema)
|
|
{
|
|
parent::__construct($schema, Audio::ATTRIBUTE_BASENAME);
|
|
}
|
|
|
|
/**
|
|
* Set the creation validation rules for the field.
|
|
*
|
|
* @param Request $request
|
|
* @return array
|
|
*/
|
|
public function getCreationRules(Request $request): array
|
|
{
|
|
return [
|
|
'required',
|
|
'string',
|
|
'max:192',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Determine if the field should be included in the select clause of our query.
|
|
*
|
|
* @param Query $query
|
|
* @param Schema $schema
|
|
* @return bool
|
|
*/
|
|
public function shouldSelect(Query $query, Schema $schema): bool
|
|
{
|
|
$linkField = new AudioLinkField($this->schema);
|
|
|
|
// The link field is dependent on this field to build the route.
|
|
return parent::shouldSelect($query, $schema) || $linkField->shouldRender($query);
|
|
}
|
|
}
|