2025-12-31 00:02:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
2026-03-22 00:56:20 +01:00
|
|
|
use App\Enums\DistributionModeEnum;
|
2025-12-31 00:02:54 +01:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2026-03-22 00:56:20 +01:00
|
|
|
use Illuminate\Validation\Rule;
|
2025-12-31 00:02:54 +01:00
|
|
|
|
|
|
|
|
class UpdateScenarioRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-03-22 00:56:20 +01:00
|
|
|
'name' => ['sometimes', 'string', 'max:255', 'min:1'],
|
|
|
|
|
'description' => ['sometimes', 'nullable', 'string', 'max:1000'],
|
|
|
|
|
'distribution_mode' => ['sometimes', 'string', Rule::in(DistributionModeEnum::values())],
|
2025-12-31 00:02:54 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function messages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'name.min' => 'The scenario name must be at least 1 character.',
|
|
|
|
|
'name.max' => 'The scenario name cannot exceed 255 characters.',
|
|
|
|
|
'description.max' => 'The description cannot exceed 1000 characters.',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
// Trim the name
|
|
|
|
|
if ($this->has('name')) {
|
|
|
|
|
$this->merge([
|
|
|
|
|
'name' => trim($this->name),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trim the description
|
|
|
|
|
if ($this->has('description')) {
|
|
|
|
|
$this->merge([
|
|
|
|
|
'description' => $this->description ? trim($this->description) : null,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|