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

sanjay1688's avatar

On redirect my session value are getting destory

I had 2 routes if i uncomment from 1 route i can able to see my session values in 1st route. But if i get redirect to my 2nd route i cant able see my session variables can any one help me out.

Route::get('/check', function(){
Session::put('id', 1); Session::put('id1', 11); //return Session::all(); return Redirect::to('/check1'); });

Route::get('/check1', function(){
return Session::all(); });

0 likes
1 reply
rodrigo.pedra's avatar

Tried it and works fine to me:

// app/Http/routes.php

    Route::get( '/check', function () {
        Session::put( 'id', 1 );
        Session::put( 'id1', 11 );

        // return Session::all();
        return Redirect::to( '/check1' );
    } );

    Route::get( '/check1', function () {
        return Session::all(); // outputs id and id1 correctly
    } );

What are your session's settings? Check your config/session.php.

If you are using the file driver, be sure to make the storage folder writable (although if it was not writable laravel would raise an exception about it ).

If you are using the array driver this is expected behavior, the array driver is useful for testing, not for developing/production.

Please or to participate in this conversation.