- (Phase 8) 后台各维度管理与配置 - (Phase 9) 全自动静默挂机修仙升级 - (Phase 9) 四大维度风云排行榜页面 - (Phase 10) 全站留言板与悄悄话私信功能 - 运行 Pint 代码格式化
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:新建聊天室请求验证器
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Http\Requests;
|
||
|
||
use Illuminate\Foundation\Http\FormRequest;
|
||
use Illuminate\Support\Facades\Auth;
|
||
|
||
class StoreRoomRequest extends FormRequest
|
||
{
|
||
/**
|
||
* Determine if the user is authorized to make this request.
|
||
*/
|
||
public function authorize(): bool
|
||
{
|
||
// 只有登录用户,且 user_level 达到特定阈值(例如 >= 10)才可以自己建房
|
||
// 具体阈值可以根据运营需求调整,此处暂设 10 为门槛。
|
||
return Auth::check() && Auth::user()->user_level >= 10;
|
||
}
|
||
|
||
/**
|
||
* Get the validation rules that apply to the request.
|
||
*
|
||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||
*/
|
||
public function rules(): array
|
||
{
|
||
return [
|
||
'name' => ['required', 'string', 'max:50', 'unique:rooms,name'],
|
||
'description' => ['nullable', 'string', 'max:255'],
|
||
];
|
||
}
|
||
|
||
public function messages(): array
|
||
{
|
||
return [
|
||
'name.required' => '必须填写房间名称。',
|
||
'name.unique' => '该房间名称已被占用。',
|
||
'name.max' => '房间名称最多 50 个字符。',
|
||
];
|
||
}
|
||
}
|