2026-04-30 09:40:50 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件功能:前台座驾购买请求验证。
|
|
|
|
|
*
|
2026-04-30 09:55:20 +08:00
|
|
|
* 校验用户购买座驾时传入的座驾与房间上下文,避免未进房直接购买聊天室座驾。
|
2026-04-30 09:40:50 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 座驾购买请求
|
2026-04-30 09:55:20 +08:00
|
|
|
* 负责校验座驾 ID 与当前房间 ID。
|
2026-04-30 09:40:50 +08:00
|
|
|
*/
|
|
|
|
|
class BuyRideRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 判断当前用户是否允许购买座驾。
|
|
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->user() !== null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取座驾购买请求验证规则。
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-04-30 09:55:20 +08:00
|
|
|
'item_id' => ['required', 'integer', 'exists:rides,id'],
|
2026-04-30 09:40:50 +08:00
|
|
|
'room_id' => ['required', 'integer', 'exists:rooms,id'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取座驾购买请求中文错误提示。
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
public function messages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'item_id.required' => '请选择要购买的座驾。',
|
|
|
|
|
'item_id.exists' => '座驾不存在或已被删除。',
|
|
|
|
|
'room_id.required' => '请先进入聊天室后再购买座驾。',
|
|
|
|
|
'room_id.exists' => '当前房间不存在。',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|