Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AO's avatar
Level 1

flash session after Sending verification email

I'm using Laravel's default auth,

And I'm redirecting the user after the registration to /email/verify/

how I can flash a session after the sending the email? instead of redirecting to /email/verify page?

thanks

0 likes
3 replies
sustained's avatar
Level 7

I believe you can add a method called registered to your Auth\RegisterController.

In the file vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers there is a method called register which validates the request, fires a Registered event, logs in the user and then the last part looks like this:

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

So what it does is it checks if the return value of calling registered is truthy then it returns that, otherwise if it is non-truthy (which is the default because by default registered does nothing) then it redirects based on the redirectPath.

And the definition of redirectPath looks like this:

    public function redirectPath()
    {
        if (method_exists($this, 'redirectTo')) {
            return $this->redirectTo();
        }

        return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
    }

So you can probably create the registered method as I said and make it look something like this:

<?php
class RegisterController extends Controller
{
    use RegistersUsers;

    protected $redirectTo = '/home';

    protected function registered(Request $request, $user)
    {
        $request->session()->flash('foo', 'bar');
        // Any other logic needed.
    }
}

And if you want it to redirect after then make sure that you return false/null/nothing and define redirectTo as either a method or a property.

Sorry if this is not super clear or if I'm incorrect or if there are easier/better ways to achieve this or whatever, I'm brand new to Laravel.

EDIT: Typos fixed.

1 like
AO's avatar
Level 1

@SUSTAINED - thanks for the reply but I tried to override registered method in register controller but it's not flashing any session :\

sustained's avatar

Can you add some kind of logging to the registered method to make sure it's getting called? Perhaps a dd or something?

1 like

Please or to participate in this conversation.