使用Laravel Auth和Eloquent在MySQL表中双行

时间:2015-01-21 23:34:00

标签: php mysql authentication laravel eloquent

我在Laravel中有一个简单的用户注册方法(下面的代码)。 我已经注意到,如果用户通过注册表单点击提交非常快速,则用户表中将有2-3个类似的行。

public function postRegister()
{
    $rules = [
        'email'                 => 'required|email|unique:users',
        'username'              => 'required|between:3,32|alpha_spaces|unique:users',
        'password'              => 'required|between:6,32',
        'password_confirmation' => 'required|same:password',
        'login'                 => 'size:0'
    ];

    $validator = Validator::make(Input::all(), $rules);

    if ($validator->fails()) {

        return Redirect::back()->withErrors($validator)->withInput();

    } else {

        $user = new User;
        $user->email = Input::get('email');
        $user->username = Input::get('username');
        $user->password = Hash::make(Input::get('password'));
        $user->save();

        Queue::push('MailController@subscribeQueue', ['email' => Input::get('email')]);

        Auth::attempt(['email' => Input::get('email'), 'password' => Input::get('password')], true);

        return Redirect::to('/')->with('good', trans('general.register.good'));
    }

0 个答案:

没有答案