File: /home/xedaptot/ai.naniguide.com/app/Http/Requests/Refactor/UpdateBrandVoiceRequest.php
<?php
namespace App\Http\Requests\Refactor;
use App\Http\Requests\Request;
/**
* Validates the brand voice settings form at
* `POST /rui/account/brand-voice`. The two lists are submitted as comma-
* separated strings from the chip-style inputs; the controller turns them
* into normalized arrays before persisting.
*/
class UpdateBrandVoiceRequest extends Request
{
public function authorize(): bool
{
return $this->user() !== null;
}
public function rules(): array
{
return [
'adjectives' => ['nullable', 'string', 'max:600'],
'forbidden' => ['nullable', 'string', 'max:600'],
'sample' => ['nullable', 'string', 'max:2000'],
];
}
/**
* @return list<string>
*/
public function adjectivesList(): array
{
return $this->parseList((string) $this->input('adjectives', ''));
}
/**
* @return list<string>
*/
public function forbiddenList(): array
{
return $this->parseList((string) $this->input('forbidden', ''));
}
public function sampleText(): ?string
{
$v = trim((string) $this->input('sample', ''));
return $v === '' ? null : $v;
}
/**
* @return list<string>
*/
private function parseList(string $raw): array
{
if ($raw === '') {
return [];
}
$items = array_map('trim', explode(',', $raw));
$items = array_filter($items, fn (string $v) => $v !== '' && mb_strlen($v) <= 40);
$items = array_values(array_unique($items));
return array_slice($items, 0, 10);
}
}