Redirection after registering with Laravel

I am using Laravel 5.

I want to redirect the user after successful registration. I tried this in my autocontroller, but it does not work.

protected $loginPath = '/plan'; protected $redirectTo = '/plan'; protected $redirectAfterRegister = 'plan/'; 

They work on a successful login, but not after registration.

I also tried postRegister render the view, but the postRegister method overrides the registration process, and I don't want to do this. I just want to redirect the user to the page upon successful registration.

+5
source share
5 answers

Overriding the postRegister function, as you mentioned, should work, you will do this in your AuthController :

  public function postRegister(Request $request) { $validator = $this->registrar->validator($request->all()); if ($validator->fails()) { $this->throwValidationException( $request, $validator ); } $this->auth->login($this->registrar->create($request->all())); // Now you can redirect! return redirect('/plan'); } 

Or something like that. Copy it from the AuthenticatesAndRegistersUsers , which is used at the top of your AuthController , here you will find all the functions

To do this, your AuthController should use the "AuthenticatesAndRegistersUsers" property, which is by default.

Additional redirection information in case you want to redirect to a named route: http://laravel.com/docs/5.0/responses#redirects

+5
source

Just add the line under AuthController to Auth / AuthController.php

 protected $redirectPath= '/plan'; 

Above redirection paths will be used for successful login and successful register.

+2
source

You can also change the register () return in RegisterUsers.php:

 public function register(Request $request) { $validator = $this->validator($request->all()); if ($validator->fails()) { $this->throwValidationException( $request, $validator ); } Auth::guard($this->getGuard())->login($this->create($request->all())); // Originally the parameter is $this->redirectPath() return redirect()->to('/plans'); } 
+1
source

Here is the laravel 5.4 solution

  /** * The user has been registered. * * @param \Illuminate\Http\Request $request * @param mixed $user * @return mixed */ protected function registered(Request $request, $user) { //User register now here you can run any code you want if (\Request::ajax()){ return response()->json([ 'auth' => auth()->check(), 'intended' => $this->redirectPath(), ]); exit(); } return redirect($this->redirectPath()); } 

keep in mind register() Process the registration request for the application. where registered() is called when the user is created.

+1
source

command after launch

 php artisan make:auth 

laravel creates an authorization controller and resource files to change the user registration route, just go the path below

 App\Http\Controllers\Auth\RegisterController 

and change protected $redirectTo and you can use this method in LoginController next to RegisterController to redirect after login

0
source

All Articles