mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-25 16:24:35 +02:00
* refactor(api): prefer composition to strict inheritance for API queries, requests & actions * style: fix StyleCI findigns
50 lines
1.0 KiB
PHP
50 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Api;
|
|
|
|
use App\Contracts\Http\Api\Field\UpdatableField;
|
|
use App\Http\Api\Field\Field;
|
|
use Illuminate\Support\Arr;
|
|
|
|
/**
|
|
* Class UpdateRequest.
|
|
*/
|
|
class UpdateRequest extends WriteRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [];
|
|
|
|
foreach ($this->schema()->fields() as $field) {
|
|
$column = $field->getColumn();
|
|
if ($field instanceof UpdatableField) {
|
|
$rules = $rules + [$column => $field->getUpdateRules($this)];
|
|
}
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
/**
|
|
* Get fields for validation preparation.
|
|
*
|
|
* @return Field[]
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
protected function getFieldsForPreparation(): array
|
|
{
|
|
return Arr::where(
|
|
$this->schema()->fields(),
|
|
fn (Field $field) => $field instanceof UpdatableField
|
|
);
|
|
}
|
|
}
|