-1

Started learning Symfony and ran into a problem. How to check if a user is logged into the site and how to get it? For example, in Laravel it is done something like this: Auth::check() or get user id: Auth::user()->id. I can use about the same thing in the blade template engine.

How can I do the same in Symfony? How can I check a user and get his object?

Sergey karpov
  • 135
  • 2
  • 6
  • https://stackoverflow.com/questions/10271570/how-to-check-if-an-user-is-logged-in-symfony2-inside-a-controller Check this – Rova Ram Aug 04 '21 at 08:39

1 Answers1

2

you can use Symfony\Component\Security\Core\Security class to get user object.

use Symfony\Component\Security\Core\Security;

class EditController extend AbstractController
{
    function create(Request $request, Security $security)
    {
        $user = $security->getUser();
    }
}