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

chanhhuynh144's avatar

Laravel 11 Session not kept after redirect

I am creating a basic login feature. I use Auth::attempt() to login and redirect to dashboard after successful login. However, there is a problem that even though the login is successful, after redirecting, the login state is no longer maintained. I did not put Auth::logout() anywhere. I made a small change in auth.php config It seems like Session doesn't retain my data. Can you help me? If you need any more information I will provide it.

Here is my code

  1. auth.php
  1. web.php
<?php

use App\Http\Controllers\Admin\AuthenticationController;
use Illuminate\Support\Facades\Route;

Route::domain(env('ADMIN_DOMAIN'))->group(function () {
    Route::prefix('auth')->name('auth.')->group(function () {
        Route::get('/login', [AuthenticationController::class, 'index'])->name('login');
        Route::post('/login', [AuthenticationController::class, 'authenticate'])->name('authenticate');
    })->middleware('guest');

    Route::middleware('auth')->group(function () {
        Route::name('dashboard.')->group(function () {
            Route::get('/', function () {
                return 1;
            })->name('index');
        });
    });
});
  1. Controller
public function authenticate(LoginRequest $request): RedirectResponse
    {
        $credential = [
            'account_id' => $request->validated('account_id'),
            'password' => $request->validated('password'),
        ];
        if(!Auth::attempt($credential, $request->validated('remember'))) {
            return $this->response(
                route('dashboard.index'),
                __('content.auth.login.failed'),
                HttpResponseCode::UNAUTHORIZED
            );
        }

        $request->session()->regenerate();

        return $this->redirectIntended(route('dashboard.index'), __('content.auth.login.success'));
    }
  1. env
0 likes
1 reply
tisuchi's avatar

@chanhhuynh144 Is that redirect to the same domain or a different domain / sub-domain?

Have you tried clearing the cache?

php artisan config:clear
php artisan cache:clear
php artisan config:cache
1 like

Please or to participate in this conversation.