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

Lars-Janssen's avatar

Create session in listener for Authenticated

Hi,

I've made a listener for the use Illuminate\Auth\Events\Authenticated event that's being fired when a user signs in.

The listener checks if the application is active it looks like this:

class CheckApplicationStatus
{
    /**
     * Check if application is active
     *
     * @param  Authenticated  $event
     * @return void
     */
    public function handle(Authenticated $event)
    {
        if(! appIsActive(settings()->active, $event->user)) {
            Auth::logout();

            return redirect('/')
                ->with(['status' => 'Applicatie is niet actief, contacteer de beheerder']);
        }

        session()->flash('status', sprintf('Welkom %s', $event->user->name));
    }
}

The problem is that when the app is NOT active it signs the user out but the session message does not show up?!

When a user signs in succesful the welcome status does show up.

The html for the session is in my app.blade so every view has it.

What could I be doing wrong here?

0 likes
3 replies
bobbybouwmann's avatar
Level 88

You send the variable $status back to the view this way. How do you access the current $status variable?

maxss's avatar

You can, with abort(redirect('/'));.

Please or to participate in this conversation.