Laravel 5.4 - 注册后禁用自动登录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43226145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.4 - Disable auto login after registration
提问by Shashika
I need to disable auto login after register an user in laravel
5.4 application. There are enough sources [example] for 5.2 and 5.3 version but it is hard find out a solution for 5.4 version.
在laravel
5.4 应用程序中注册用户后,我需要禁用自动登录。5.2 和 5.3 版本有足够的来源 [ example],但很难找到 5.4 版本的解决方案。
In Laravel 5.4 there is no AuthController
as it divided to LoginController
and RegisterController
. Guide me to disable auto login in laravel 5.4.
在 Laravel 5.4 中没有,AuthController
因为它分为LoginController
和RegisterController
。指导我在 laravel 5.4 中禁用自动登录。
回答by Ivanka Todorova
Since your RegisterController
uses RegistersUsers
trait, all of the trait's methods are available to RegisterController
. The method you need to override, in order to prevent users to be logged in after they successfully registered is register()
. Here's the initial body of the method:
由于您RegisterController
使用了RegistersUsers
trait,所有 trait 的方法都可用于RegisterController
. 您需要覆盖的方法是register()
. 这是该方法的初始主体:
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
The line: $this->guard()->login($user);
is where the user gets logged in. You can either remove it or modify it to suit your needs.
行:$this->guard()->login($user);
是用户登录的地方。您可以删除它或修改它以满足您的需要。
回答by Akbar Mirsiddikov
If you use default register route you can do it like this...
如果您使用默认注册路由,您可以这样做...
in RegistersUsers.php
file
在RegistersUsers.php
文件中
comment this line in register
function
在register
函数中注释这一行
$this->guard()->login($user);
I hope this helps you!!
我希望这可以帮助你!!
回答by Mego
how it goes about Laravel 6? I try to do the same thing. However, I don't think, rewritting in /vendor/... folder is good practise. I tried to overwrite function "registered", but when I define a protected function registered(...) {...} in my App/http/Controller/Auth/RegisterController.php I receive an error
Laravel 6 怎么样?我尝试做同样的事情。但是,我不认为,在 /vendor/... 文件夹中重写是一种很好的做法。我试图覆盖函数“注册”,但是当我在我的 App/http/Controller/Auth/RegisterController.php 中定义一个受保护的函数 Registration(...) {...} 时,我收到一个错误
Argument 1 passed to App\Http\Controllers\Auth\RegisterController::registered() must be an instance of App\Http\Controllers\Auth\Request, instance of Illuminate\Http\Request given, called in C:\wamp\www\presbyteria\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php on line 35
回答by Elrayah Elshikh
I've added Auth::logout();
next to the guard in the new versions.
我Auth::logout();
在新版本的守卫旁边添加了。
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
\Auth::logout();
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
回答by Pankit Gami
You can change the $redirectTo
url
in the RegisterController
to your url.
Or You can override registered
method of the RegistersUsers
trait in RegisterController
.
您可以将$redirectTo
url
中的更改RegisterController
为您的网址。或者,您可以覆盖registered
该方法RegistersUsers
的特点RegisterController
。