mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Api;
|
|
|
|
use App\Contracts\Http\Api\InteractsWithSchema;
|
|
use App\Http\Api\Schema\Schema;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use RuntimeException;
|
|
|
|
abstract class BaseRequest extends FormRequest
|
|
{
|
|
/**
|
|
* The underlying schema used to perform validation.
|
|
*/
|
|
protected Schema $schema;
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
abstract public function rules(): array;
|
|
|
|
/**
|
|
* Get the underlying schema.
|
|
*/
|
|
public function schema(): Schema
|
|
{
|
|
return $this->schema;
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
parent::prepareForValidation();
|
|
|
|
$controller = $this->route()->getController();
|
|
|
|
if (! $controller instanceof InteractsWithSchema) {
|
|
throw new RuntimeException("Cannot resolve schema for controller '{$this->route()->getControllerClass()}'");
|
|
}
|
|
|
|
$this->schema = $controller->schema();
|
|
}
|
|
}
|