66 lines
1.9 KiB
PHP
66 lines
1.9 KiB
PHP
|
|
<?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 StoreExchangeGoods 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 [
|
||
|
|
'title'=>'required|max:50',
|
||
|
|
'pic'=>'required|url',
|
||
|
|
'price'=>'required|numeric',
|
||
|
|
'coin_num'=> 'required|numeric',
|
||
|
|
'stock'=>'required|numeric',
|
||
|
|
'intro'=>'nullable',
|
||
|
|
'is_sale'=>'required|boolean'
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function messages()
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'title.required' => '请输入商品名称',
|
||
|
|
'title.max' => '输入商品名称过长',
|
||
|
|
'pic.required' => '请上传商品图片',
|
||
|
|
'pic.url' => '商品图片无效',
|
||
|
|
'price.required' => '请输入商品价格',
|
||
|
|
'price.numeric' => '输入的价格必须是数字',
|
||
|
|
'coin_num.required' => '请输入商品抵扣福币数量',
|
||
|
|
'coin_num.numeric' => '输入的福币数量必须是数字',
|
||
|
|
'stock.required' => '请输入商品库存数量',
|
||
|
|
'stock.numeric' => '输入的库存数量必须是数字',
|
||
|
|
'is_sale.required' => '请选择商品是否上下架',
|
||
|
|
'is_sale.boolean' => '商品是否上下架为bool值',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function failedValidation(Validator $validator)
|
||
|
|
{
|
||
|
|
$msg = $validator->errors()->first();
|
||
|
|
throw new HttpResponseException($this->failure($msg));
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|