Symfony EventListner to write somethigng to database

I am now stepping into Symfony’s EventListener and below are the code snippets:

// service.yaml
AppEventListenerAuthenticationListener:
  tags: 
    - {name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin}
//AuthenticationListener.php
class AuthenticationListener {
  public function onInteractiveLogin(InteractiveLoginEvent $e) {
    $token=$e->getAuthenticationToken();
    $user=$token->getUser();
    ....
  }
}

These codes worked well and got triggered properly. Now, I want to add some code in that onInteractiveLogin function so that it can update the user (an AppEnityUser entity) so that its last_login field (this field is in the user table) gets updated.

Please throw in some hints. Thanks.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *