PromptVault/app/Http/Requests/PromptFormRequest.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2026-10-26 20:12:16 +00:00
<?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',
],
];
}
}