generated from liutk/owl-admin-base
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
|
|
class UserInfoRequest 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 [
|
|
//
|
|
'avatar'=> 'required|url',
|
|
'nick_name' => 'required|max:10',
|
|
];
|
|
}
|
|
|
|
public function messages(){
|
|
$messages = [
|
|
'avatar.required'=>'请选择头像',
|
|
'avatar.url'=>'头像参数错误',
|
|
'nick_name.required'=>'昵称必填',
|
|
'nick_name.max'=>'昵称长度不能超过10位',
|
|
];
|
|
return $messages;
|
|
}
|
|
|
|
protected function failedValidation(Validator $validator){
|
|
$error = $validator->errors()->all();
|
|
throw new HttpResponseException(response()->json(['data' => [], 'code' => 400, 'message' => $error[0]]));
|
|
}
|
|
}
|