Home > Net >  how to change redirect after auth Email verification in laravel 8?
how to change redirect after auth Email verification in laravel 8?

Time:04-08

I have 2 condition after successful registration with email verification.

  1. If the new user is select plan from home page, redirects to registration page submits the form. then will get Email verfication link, and after email verified I want to redirect directly to checkout. Plan id will be saving session , so I can get all the details of plan.
  2. If the new user is not select plan from home page, then he can sign up and redirects to dashboard

But in laravel after email verfication always redirects to home page. But I dont want to redirect to home page again.

How can be this done? Wher can do the coding part?

Verification Controller


 use VerifiesEmails;

    /**
     * Where to redirect users after verification.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }
    
    protected function verified(Request $request)
    {
        $request->session()->flash('alert','Your Email is verfied');
    }


Routes

  public function emailVerification()
    {
        return function () {
            $this->get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
            $this->get('email/verify/{id}/{hash}', 'Auth\VerificationController@verify')->name('verification.verify');
            $this->post('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
        };
    }

CodePudding user response:

Couple approaches from what I can see...

  1. In your controller actions where you are routing them to Auth\VerificationController@verify do the check to make sure a flag isn't already set, set the flag if it isn't set, put your redirect after that logic. So it would be something like this for a route...

    return redirect()->route('route.name', [$veriYouWantToSendAlong]);

Or to a static page with errors.

return redirect()->route('page/name')->withErrors(['Some error here']);
  1. In your Laravel auth controller should be a protected $redirectTo = '/home'; action you can change that to dashboard or wherever you'd like to send them after log in.

CodePudding user response:

Add a method called redirectTo(). It will be called if it exists.

public function redirectTo()
{
   // put your routing logic here
}

The function should return a string of the url to go to.

  • Related