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

46 lines
1.0 KiB
PHP
Raw Normal View History

2020-05-06 03:55:40 +00:00
<?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',
];
}
2020-05-11 09:16:17 +00:00
public function attributes()
{
return [
'nickname' => '昵称',
];
}
2020-05-06 03:55:40 +00:00
protected function failedValidation(Validator $validator)
{
throw new HttpResponseException(response()->json(['code'=>1,'msg'=>$validator->errors()->first()]));
}
}