title: Symfony 4 get user Entity by id
body: <p>I'm trying to make a simple Many-To-Many relation, the goal is to Add a friend into the Database.</p>
  <p>I'm trying to add a friend using my Controller but i can't find a way to get User entity using the ID.</p>
  <p>Following the example in the docs:</p>
  <pre class="lang-php prettyprint-override"><code>    /**
       * @Entity
       */
      class User
      {
          /**
           * @Id
           * @Column(type=&quot;integer&quot;)
           */
          private $id;
      
          /**
           * @ManyToMany(targetEntity=&quot;User&quot;)
           * @JoinTable(name=&quot;friends&quot;,
           *     joinColumns={@JoinColumn(name=&quot;user_a_id&quot;, referencedColumnName=&quot;id&quot;)},
           *     inverseJoinColumns={@JoinColumn(name=&quot;user_b_id&quot;, referencedColumnName=&quot;id&quot;)}
           * )
           * @var \Doctrine\Common\Collections\ArrayCollection
           */
          private $friends;
      
          /**
           * Constructor.
           */
          public function __construct()
          {
              $this-&gt;friends = new \Doctrine\Common\Collections\ArrayCollection();
          }
      
          /**
           * @return array
           */
          public function getFriends()
          {
              return $this-&gt;friends-&gt;toArray();
          }
      
          /**
           * @param  User $user
           * @return void
           */
          public function addFriend(User $user)
          {
              if (!$this-&gt;friends-&gt;contains($user)) {
                  $this-&gt;friends-&gt;add($user);
                  $user-&gt;addFriend($this);
              }
          }
      
          /**
           * @param  User $user
           * @return void
           */
          public function removeFriend(User $user)
          {
              if ($this-&gt;friends-&gt;contains($user)) {
                  $this-&gt;friends-&gt;removeElement($user);
                  $user-&gt;removeFriend($this);
              }
          }
  
  </code></pre>
  <p>And my Controller :</p>
  <pre class="lang-php prettyprint-override"><code>        /**
           * @Route(&quot;/addFriends&quot;)
           */
          public function addFriends()
          {
              if (isset($_POST['add'])) {
                  $id = $_POST['id'];
                  $user = $this-&gt;getUser();
                  $user-&gt;addFriend($id);
              }
              return $this-&gt;redirectToRoute('friends');
          }
  </code></pre>
  <p>Instead of the <code>$id</code> Symfony wants me to use an instance of entity :
  Argument 1 passed to <code>App\Entity\User::addFriend()</code> must be an instance of App\Entity\User, string given and I can't find a way to use one.</p>