Files
chatroom/app/Http/Requests/UpdateChatPreferencesRequest.php
T

63 lines
1.9 KiB
PHP

<?php
/**
* 文件功能:聊天室偏好设置验证器
* 负责校验用户提交的屏蔽播报、禁音与聊天室字号配置。
*/
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
/**
* 聊天室偏好设置验证器
* 仅允许提交白名单内的屏蔽项、布尔型禁音状态与合法字号。
*/
class UpdateChatPreferencesRequest extends FormRequest
{
/**
* 允许已登录用户保存自己的聊天室偏好。
*/
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* 获取聊天室偏好的验证规则。
*
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'blocked_system_senders' => ['nullable', 'array'],
'blocked_system_senders.*' => [
'string',
Rule::in(['钓鱼播报', '猜成语', '猜谜活动', '星海小博士', '百家乐', '跑马', '神秘箱子', '五子棋', '老虎机', '双色球彩票']),
],
'sound_muted' => ['required', 'boolean'],
'font_size' => ['nullable', 'integer', 'min:10', 'max:30'],
];
}
/**
* 获取聊天室偏好的中文错误提示。
*
* @return array<string, string>
*/
public function messages(): array
{
return [
'blocked_system_senders.array' => '屏蔽设置格式无效。',
'blocked_system_senders.*.in' => '存在不支持的屏蔽项目。',
'sound_muted.required' => '请传入禁音状态。',
'sound_muted.boolean' => '禁音状态格式无效。',
'font_size.integer' => '聊天室字号格式无效。',
'font_size.min' => '聊天室字号不能小于 10。',
'font_size.max' => '聊天室字号不能大于 30。',
];
}
}