Ranjeet
4 years ago
523
9
Laravel

How to store users id in Session table Laravel 5

Posted 4 years ago by Ranjeet

I want to check online users by storing user id in session table when user logged in i have made a session.table

php artisan session:table

i have added user_id column in migration file and it looks like this

<?php

use Illuminate\Database\Migrations\Migration;

class CreateSessionTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('sessions', function($t)
        {
            $t->string('id')->unique();
            $t->text('payload');
            $t->integer('last_activity');
            $t->integer('user_id')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('sessions');
    }

}

Then i made migration

php artisan migrate

I have made model for it,, named online

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Online extends Model{
    protected $table = "sessions";
    protected $timestamps = false;
    protected $fillable = ['user_id'];
}

Now what i should do to store logged in user id into session table

Please sign in or create an account to participate in this conversation.