42 lines
1 KiB
PHP
42 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreScenarioRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
// In production, check if user is authenticated
|
|
// For now, allow all requests
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:255', 'min:1'],
|
|
'description' => ['nullable', 'string', 'max:1000'],
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => 'A scenario name is required.',
|
|
'name.min' => 'The scenario name must be at least 1 character.',
|
|
'name.max' => 'The scenario name cannot exceed 255 characters.',
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
// Trim the name
|
|
if ($this->has('name')) {
|
|
$this->merge([
|
|
'name' => trim($this->name),
|
|
]);
|
|
}
|
|
}
|
|
}
|