$user = Auth::getCurrent(); echo $user->name;
$user = $this->get('security.token_storage')->getToken()->getUser(); echo $user->getName();In this example, we are using the getCurrent() method to retrieve the logged-in user's object and then printing their name. Overall, the getCurrent() method is a useful tool for retrieving user information depending on the package library you are using in your PHP application.