40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests;
|
||
|
|
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Shared validation for prompt create/update payloads.
|
||
|
|
*/
|
||
|
|
abstract class PromptFormRequest extends FormRequest
|
||
|
|
{
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return array<string, list<string>>
|
||
|
|
*/
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'name' => ['required', 'string', 'max:120'],
|
||
|
|
'description' => ['nullable', 'string', 'max:500'],
|
||
|
|
'body' => ['required', 'string'],
|
||
|
|
'tags' => ['nullable', 'array'],
|
||
|
|
// Global middleware (TrimStrings + ConvertEmptyStringsToNull) rewrites
|
||
|
|
// empty/whitespace-only entries to null before validation, so null is
|
||
|
|
// accepted and stripped during normalization (PromptService::tagIds);
|
||
|
|
// other non-strings are rejected.
|
||
|
|
'tags.*' => [
|
||
|
|
fn ($attribute, $value, $fail) => $value !== null && ! is_string($value)
|
||
|
|
? $fail('Each tag must be a string.')
|
||
|
|
: true,
|
||
|
|
'max:40',
|
||
|
|
],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|