sessionid is the id of the session, not the user
Try Auth::user()->id;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, Im trying to pass the session id to the /listeners/LogSuccessfulLogin, so when the user logins it's store in the DB, but when I complete the login and echo the session()->getId() in the view, it's different, is there any way to get the correct id in the listener?
Providers\EventServiceProvider
protected $listen = [
'Illuminate\Auth\Events\Login' => [
'App\Listeners\LogSuccessfulLogin',
],
];
Listeners\LogSuccessfulLogin
public function __construct(Request $request)
{
$this->request = $request;
}
public function handle(Login $event)
{
$id = $event->user->id; //this works
//$session = (auth()->check()) ? auth()->session()->getId() : null;
$session = session()->getId(); //this is the wrong id
}
Appreciate any help
Then just create your own token (or the ID from your logins table) and save it in the session.
You can then always retrieve it at logout.
Please or to participate in this conversation.