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

Kaustubh's avatar

Session Table Columns

Hi,

I am new to laravel session. I created session table but i dont know the columns use in session table.

Schema::create('sessions', function ($table) {
    $table->string('id')->unique();
    $table->unsignedInteger('user_id')->nullable();
    $table->string('ip_address', 45)->nullable();
    $table->text('user_agent')->nullable();
    $table->text('payload');
    $table->integer('last_activity');
});

what data user agent and payload store.

I have another question, i dont want to store user login session in session table. I have cart and want to store only cart in session. so how can i store only cart session in table and not user session.

0 likes
1 reply
sherwinmdev's avatar
Level 6

@Kaustubh you can find out what is stored in each column at Illuminate/Session/DatabaseSessionHandler i think. but user_agent stores information about the user's browsers. payload contains the all of the information collected and it's base64 encoded.

you don't have to use the default sessions table to store you cart information. but i don't believe you could change the functionality without writing your own or using a a plugin. i could be wrong but it's part of the "core" functionality. you could create your own cart class and have it work the way you want or use a package. there's plenty of packages https://laracasts.com/discuss/channels/general-discussion/simple-shopping-cart.

to try and answer your question, you can create a session with the cart information and store it in the database. you can create a model and do as follows.

class Cart extends Model {
    public static function addToCart($request)
    {
        // create the session
        $request->session->put('key', 'value');
        
        // then do your insert to the database
    }

    public static function removeFromCart($request)
    {
        // remove key from session

        // update database session
    }
}

// and so on...

https://laravel.com/docs/5.4/session#using-the-session

there isn't really a short and simple approach. you can roll your own or use a package. hope that helps get you started.

Please or to participate in this conversation.