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

Ifrit's avatar
Level 2

Destroying session

Is there a way to destroy a session when logging out of a logged in section. I've done this

public function doLogout(){
        //Allows the user to log out
        Auth::logout();
        return redirect()->route('login');
    }

But I'm still able to go to the logged in page through the url.

Here is my routes

Route::group(['middleware' => ['accountActivated']], function()
{
    Route::get('/dashboard/home', [
        'uses' => 'AuthorsController@dashboard',
        'as' => 'dashboard'
    ]);

    Route::resource('dashboard/stories', 'StoryController');

    Route::resource('dashboard/clients', 'clientsController');

    Route::get('dashboard/logout', [
            'uses' => 'AuthorsController@doLogout',
            'as' => 'logout'
        ]);

});

and this is my middleware called AccountActivated.php

public function handle($request, Closure $next, $guard = 'authors_admin')
    {
        
        if(!Auth::guard($guard)->check()){
            return redirect()->to('login')->with('success', 'Denied was a success');
        }

        return $next($request);
    }
0 likes
0 replies

Please or to participate in this conversation.