love_php/app/Http/Requests/ExchangeGoodsRequest.php

55 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Http\Requests;
use App\Http\Response\ResponseJson;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class ExchangeGoodsRequest extends FormRequest
{
use ResponseJson;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'num' => 'required|numeric',
'name' => 'required',
'mobile'=> 'required|numeric',
'address'=> 'required',
];
}
public function messages()
{
return [
'num.required' =>'请选择兑换商品数量',
'num.numeric' =>'请选择正确兑换商品数量',
'name.required'=>'请输入联系人姓名',
'mobile.required'=>'请输入联系人手机号',
'mobile.numeric'=>'请输入联系人正确的手机号',
'address.required'=>'请输入联系人地址',
];
}
public function failedValidation(Validator $validator)
{
$msg = $validator->errors()->first();
throw new HttpResponseException($this->failure($msg));
}
}