UsersRequest.php 1.24 KB
Newer Older
冯超鹏's avatar
冯超鹏 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UsersRequest 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 [
            'username'=>'required|between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:BackgroundUser,username',
            'password'=>'required|string|min:6',
            'phone'=> 'required|regex:/^1[3465789]\d{9}$/|unique:phone',
            'email'=>'email',
        ];
    }
    //自定义提示
    public function messages()
    {
        return [
            'username.required' => '用户名不能为空!',
            'password.required' => '密码不能为空!',
            'password.between' => '密码需要在2到8位之间',
            'password.confirmed' => '两次密码不一致',
            'password_confirmation.required' => '确认密码不能为空!',
            'email.required' => '邮箱不能为空!',
            'email.email' => '邮箱格式不正确!'
        ];
    }
}