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 个字符。',
|
|||
|
|
];
|
|||
|
|
}
|
|||
|
|
}
|