新增聊天室状态与功能快捷菜单
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:聊天室用户状态设置验证器
|
||||
* 负责校验用户在聊天室内提交的当日状态设置与清除请求。
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Support\ChatDailyStatusCatalog;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateDailyStatusRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* 允许已登录用户保存自己的当日状态。
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天室当日状态设置的验证规则。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'room_id' => ['required', 'integer', 'exists:rooms,id'],
|
||||
'action' => ['required', 'string', Rule::in(['set', 'clear'])],
|
||||
'status_key' => [
|
||||
Rule::requiredIf(fn (): bool => $this->input('action') === 'set'),
|
||||
'nullable',
|
||||
'string',
|
||||
Rule::in(ChatDailyStatusCatalog::keys()),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天室当日状态设置的中文错误提示。
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'room_id.required' => '缺少当前房间信息。',
|
||||
'room_id.integer' => '房间编号格式无效。',
|
||||
'room_id.exists' => '当前房间不存在。',
|
||||
'action.required' => '缺少状态操作类型。',
|
||||
'action.in' => '不支持的状态操作类型。',
|
||||
'status_key.required' => '请选择要设置的状态。',
|
||||
'status_key.in' => '请选择系统支持的状态。',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user