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

sanjay1688's avatar

laravel session expire on redirect

Hey i m having routes in my route file

Route::get('login', array('as' => 'show.login', 'uses' => 'HomeController@showLogin')); Route::post('login', array('as' => 'do.login', 'uses' => 'HomeController@doLogin')); Route::get('/', array('as' => 'home.home','uses' => 'HomeController@home'));

Insdie my home controller

public function doLogin(){ $rules = array('email' => 'required|email','password' => 'required');

$validator = Validator::make(Input::all(), $rules);

if ($validator->fails()) {

    return Redirect::to('login')->withErrors($validator)->withInput(Input::except('password')); 
} else {

    $user           =   Customeruser::where('email', Input::get('email'))->first();

    if(!$user) {
        $attempt = false;
    } else {
        $attempt = Auth::attempt(array('email' => Input::get('email') , 'password' => Input::get('password') ));
    }       

    if($attempt) {
        
        //Session::flush();
        Session::put('user_id', Auth::user()->uuid);
        Session::put('user_name', Auth::user()->first_name." ".Auth::user()->last_name);
        Session::put('user_email', Auth::user()->email);
        // return Session::all();
        // return Redirect::to('/')->with(array('message' => 'Successfully logged in!', 'flash_type' => 'success'));
        $occasions      =   Occasion::with('occasioncategory')->active()->latest()->take(8)->get(); 
        return View::make('home.home' , compact('occasions')); 

        return Redirect::to('/')->with(array('message' => 'Successfully logged in!', 'flash_type' => 'success'));
    }

    return Redirect::back()->with(array('message' => 'Invalid credentials, please try again'))->withInput();

}

}

public function home() { return Session::all(); }

if retrun return Session::all(); from doLogin function before redirect i can able print session on browser as soon as i redirect i can't able to see my session

What is the issuse can anybody helpme out

0 likes
1 reply
guillefd's avatar

I have the same issue right now, but noticed that if I visit the login page before (/auth/login without login in) and then running my controller, the session is stored. Maybe someting related to session initialization ?

Session dump, but doesnt persist

Session dump, after visiting /auth/login (without login in), session persist

Please or to participate in this conversation.