<?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' => '邮箱格式不正确！'
        ];
    }
}
