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

devondahon's avatar

Can I get all sessions of a given user with Facade\Session ?

Can I get all sessions of a given user using Illuminate\Support\Facades\Session instead of DB like below ?

Illuminate\Support\Facades\DB::table('sessions')->whereUserId($user_id)->get('id')
0 likes
6 replies
devondahon's avatar

@denniseilander Thanks for your answer, but I don't think so because my $request is actually linked to api.driver.passport guard (the request is made via Laravel Passport, so it's not based on Http session).

RuskinF's avatar

Yes, you can use Illuminate\Support\Facades\Username\Session instead of DB in your code to get all the sessions of the user.

MichalOravec's avatar
DB::table('sessions')->where('user_id', $user_id)->get();

or you can create your own model for example SessionDb

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class SessionDb extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'sessions';
}

Then you can use it like

SessionDb::where('user_id', $user_id)->get();
devondahon's avatar

Thanks, I thought the Session class may have such method.

Please or to participate in this conversation.