I want to return all Logged in users of my application and render it in my Dashboard. The user_id and user_name should be retrieve
In Symfony 4 I solved the problem in the following way.
em = $em;
$this->security = $security;
}
public function onTerminate() {
$user = $this->security->getUser();
if (!$user->isActiveNow()) {
$user->setLastActivityAt(new \DateTime());
$this->em->persist($user);
$this->em->flush($user);
}
}
public static function getSubscribedEvents() {
return [
// must be registered before (i.e. with a higher priority than) the default Locale listener
KernelEvents::TERMINATE => [['onTerminate', 20]],
];
}
}