簡體   English   中英

注冊后立即登錄用戶 - laravel

[英]Login user right after registration - laravel

我正在嘗試使用以下代碼注冊后立即登錄用戶。
我在我的代碼中沒有看到任何錯誤,因為我收到以下錯誤

方法 [guard] 不存在。

我也有進口用途

Illuminate\Contracts\Auth\Guard;

注冊用戶

public function register(Request $request)
{
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    // $this->create($request->all());
    $user = $this->create($request->all());

    UserVerification::generate($user);
    UserVerification::send($user, 'My Custom E-mail Subject');

    $this->guard()->login($user)->with('status', 'Registration successfully done.');

    return $this->registered($request, $user)
        ?: redirect($this->redirectPath());

}

您的控制器中沒有名為guard方法。 使用Authlogin方法。
使用Auth::login($user); 手動登錄用戶

public function register(Request $request)
{
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    // $this->create($request->all());
    $user = $this->create($request->all());

    UserVerification::generate($user);
    UserVerification::send($user, 'My Custom E-mail Subject');

    \Auth::login($user);

    return $this->registered($request, $user)
        ?: redirect($this->redirectPath());

}

如果你想使用自定義守衛,你可以指定守衛Auth::guard('guard-name')->login($user)

注冊后,如果您的自定義防護不起作用,請在您的自定義注冊控制器中將此功能放在下面,它將為您工作。 注冊后,您的自定義警衛將 100% 工作。

protected function guard(){return Auth::guard('dealer');}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM