hujiao-gui/app/Http/Requests/Admin/User/UpdateRequest.php

46 lines
1.0 KiB
PHP

<?php
namespace App\Http\Requests\Admin\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
class UpdateRequest extends FormRequest
{
/**
* 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 [
'phone' => 'required|numeric|regex:/^1[34578][0-9]{9}$/|unique:users,phone,'.$this->id.',id',
'nickname' => 'required|min:4|max:14',
];
}
public function attributes()
{
return [
'nickname' => '昵称',
];
}
protected function failedValidation(Validator $validator)
{
throw new HttpResponseException(response()->json(['code'=>1,'msg'=>$validator->errors()->first()]));
}
}