Laravel 5.4 - Disable automatic login after registration
I need to disable automatic login after user registration in app laravel
5.4. Enough sources [ example ] for version 5.2 and 5.3, but hard to find a solution for version 5.4.
Not in Laravel 5.4 AuthController
as it is split into LoginController
and RegisterController
. Guide me to disable auto login in laravel 5.4.
Since yours RegisterController
uses a trait RegistersUsers
, all trait methods are available for RegisterController
. The method that you must override, so that users can not log on after a successful registration register()
. Here's the original body of the method:
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());
}
Line: $this->guard()->login($user);
This is where the user logs in. You can either delete it or change it to suit your needs.
If you are using the default registration route, you can do it like this ...
in file RegistersUsers.php
comment out this line in the function register
$this->guard()->login($user);
I hope this helps you!
what about Laravel 6? I am trying to do the same. However, I don't think rewriting in the / vendor / ... folder is good practice. I tried to overwrite the "registered" function, but when I define a protected function registered (...) {...} in my app /http/Controller/Auth/RegisterController.php, I get the error
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
You can change $redirectTo
url
in RegisterController
to your url. Or you can override the method registered
in RegistersUsers
the RegisterController
.