2026-08-23 10:04:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
|
|
|
|
|
class FindAnagramWordsRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-08-23 21:46:14 +02:00
|
|
|
'anagram' => ['required', 'string', 'alpha:ascii', 'min:2', 'max:24'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function messages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'anagram.alpha' => 'Letters only — no digits, spaces or punctuation.',
|
|
|
|
|
'anagram.max' => 'That is longer than any word in the dictionary.',
|
2026-08-23 10:04:08 +02:00
|
|
|
];
|
|
|
|
|
}
|
2026-08-23 21:46:14 +02:00
|
|
|
|
|
|
|
|
// The dictionary is lowercase and Matcher::check compares raw characters,
|
|
|
|
|
// so an uppercase anagram would silently return nothing.
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'anagram' => strtolower((string) $this->input('anagram', '')),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2026-08-23 10:04:08 +02:00
|
|
|
}
|