Just adding it in the migration (creating the field in the table) isn't going to populate it. You'd need to add it into the session driver as well so it would write a value when the session is created. However, every visitor gets a session, not just logged in users, so this wouldn't work very well since there wouldn't be a user_id for users who aren't logged in.
It would be better to remove that user_id, and just query the session table directly for sessions where last_activity is within some time range, like within the last 5 or 10 minutes. That would give you how many users are logged in to application on current time
@Cronix Thanks for your Reply i think you are right user_id doesn't make sense if there are request without logged in users.
I had taken that user_id field because to query directly on last_activity and then get count of that user_id, so it can't slow down the query at least as per my knowledge.
It looks ok. If you have a lot of visitors, you might consider caching that result for 10 minutes so you're not hitting the db and going through that loop each time you need the data. It's kind of an expensive thing to do with all of the decoding and checking values. https://laravel.com/docs/5.6/cache