70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UserRequest 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()
|
|
{
|
|
|
|
switch ($this->method()) {
|
|
case 'POSt':
|
|
return [
|
|
'name' => 'required|string|max:255',
|
|
'password' => 'required|string|min:6',
|
|
'verification_key' => 'required|string',
|
|
'verification_code' => 'required|string',
|
|
];
|
|
case 'PATCH':
|
|
$user_id = \Auth::guard('api')->id();
|
|
return [
|
|
'name' => 'between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name,' . $user_id,
|
|
'email' => 'email',
|
|
'introduction' => 'max:80',
|
|
'avatar_image_id' => 'exists:images,id,type,avatar,user_id,' . $user_id,
|
|
];
|
|
default:
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function attributes()
|
|
{
|
|
return [
|
|
'verification_key' => '短信验证码 key',
|
|
'verification_code' => '短信验证码',
|
|
'introduction' => '个人简介',
|
|
];
|
|
}
|
|
|
|
public function messages()
|
|
{
|
|
return [
|
|
'name.unique' => '用户名已被占用,请重新填写',
|
|
'name.regex' => '用户名只支持英文、数字、横杆和下划线。',
|
|
'name.between' => '用户名必须介于 3 - 25 个字符之间。',
|
|
'name.required' => '用户名不能为空。',
|
|
];
|
|
}
|
|
}
|