Laravel 5.6注册后自动登录

时间:2019-01-02 08:23:05

标签: laravel

我正在尝试在注册后自动登录用户。从我从其他答案中发现的结果来看,类似的方法应该起作用,但事实并非如此。

protected function create(array $data)
{
    $user = User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ]); 

    Auth::loginUsingId($user->id);
}

它正在添加新用户,但未登录。它还重定向到正确的页面。它也使用ajax来注册用户

$.ajax({
    url: "userregister",
    data: {_token:_token,useremail:useremail,userpassword:userpassword},
    type: 'POST',
    beforeSend: function () {
        $("#showloadinsignup").html('<img src="'+site_url+'/public/images/loading.gif">');
    },
    success: function (result) {
        if(result == "useraddsucess"){
            $("#showloadinsignup").html('');
            $("#emailerror").html('');
            $("#success").html("<div class='alert alert-success fade in'><a href='#' class='close' data-dismiss='alert'>&times;</a><strong>Success!</strong> User Registered.</div>");
            $("html, body").animate({ scrollTop: 0 }, "slow");
            formid.reset();
}

0 个答案:

没有答案
相关问题