fedi-feed-router/app/Http/Requests/StorePlatformChannelRequest.php

48 lines
1.5 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StorePlatformChannelRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, array<int, mixed>|string>
*/
public function rules(): array
{
return [
'platform_instance_id' => 'required|exists:platform_instances,id',
// name doubles as the Lemmy community slug (CreateChannelAction copies it
// verbatim into channel_id for community lookup at publish time), so it must
// be slug format and unique per instance — matching the Livewire create form.
'name' => [
'required',
'string',
'max:255',
'regex:/^[a-z0-9_]+$/',
Rule::unique('platform_channels', 'name')
->where('platform_instance_id', $this->input('platform_instance_id')),
],
'language_id' => 'nullable|exists:languages,id',
'description' => 'nullable|string',
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'name.regex' => 'The name must be a valid community slug (lowercase letters, numbers, and underscores only).',
'name.unique' => 'A channel with this name already exists for this instance.',
];
}
}