mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-20 17:49:20 +02:00
78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Api\Field\Wiki\Video\Script;
|
|
|
|
use App\Contracts\Http\Api\Field\CreatableField;
|
|
use App\Contracts\Http\Api\Field\SelectableField;
|
|
use App\Contracts\Http\Api\Field\UpdatableField;
|
|
use App\Http\Api\Field\Field;
|
|
use App\Http\Api\Query\Query;
|
|
use App\Http\Api\Schema\Schema;
|
|
use App\Models\Wiki\Video;
|
|
use App\Models\Wiki\Video\VideoScript;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
/**
|
|
* Class ScriptVideoIdField.
|
|
*/
|
|
class ScriptVideoIdField extends Field implements CreatableField, SelectableField, UpdatableField
|
|
{
|
|
/**
|
|
* Create a new field instance.
|
|
*
|
|
* @param Schema $schema
|
|
*/
|
|
public function __construct(Schema $schema)
|
|
{
|
|
parent::__construct($schema, VideoScript::ATTRIBUTE_VIDEO);
|
|
}
|
|
|
|
/**
|
|
* Set the creation validation rules for the field.
|
|
*
|
|
* @param Request $request
|
|
* @return array
|
|
*/
|
|
public function getCreationRules(Request $request): array
|
|
{
|
|
return [
|
|
'sometimes',
|
|
'required',
|
|
'integer',
|
|
Rule::exists(Video::class, Video::ATTRIBUTE_ID),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
{
|
|
// Needed to match video relation.
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Set the update validation rules for the field.
|
|
*
|
|
* @param Request $request
|
|
* @return array
|
|
*/
|
|
public function getUpdateRules(Request $request): array
|
|
{
|
|
return [
|
|
'sometimes',
|
|
'required',
|
|
'integer',
|
|
Rule::exists(Video::class, Video::ATTRIBUTE_ID),
|
|
];
|
|
}
|
|
}
|