src/Entity/Follow.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity(repositoryClass="App\Repository\FollowRepository")
  7.  */
  8. class Follow
  9. {
  10.     /**
  11.      * @ORM\Id()
  12.      * @ORM\GeneratedValue()
  13.      * @ORM\Column(type="integer")
  14.      */
  15.     private $id;
  16.     /**
  17.      * @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="follows",cascade={"persist"})
  18.      */
  19.     private $followers;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      */
  23.     private $following;
  24.     public function getId(): ?int
  25.     {
  26.         return $this->id;
  27.     }
  28.     public function __construct()
  29.     {
  30.         $this->followers = new ArrayCollection();
  31.     }
  32.     public function getFollowing(): ?string
  33.     {
  34.         return $this->following;
  35.     }
  36.     public function setFollowing(string $following): self
  37.     {
  38.         $this->following $following;
  39.         return $this;
  40.     }
  41.     /**
  42.      * @return mixed
  43.      */
  44.     public function getFollowers()
  45.     {
  46.         return $this->followers;
  47.     }
  48.     public function addFollower(User $follower): self
  49.     {
  50.         if (!$this->followers->contains($follower)) {
  51.             $this->followers[] = $follower;
  52.             $follower->addFollow($this);
  53.         }
  54.         return $this;
  55.     }
  56.     public function removeFollower(User $follower): self
  57.     {
  58.         if ($this->followers->contains($follower)) {
  59.             $this->followers->removeElement($follower);
  60.             $follower->removeFollow($this);
  61.         }
  62.         return $this;
  63.     }
  64.     public function __toString()
  65.     {
  66.         return $this->getFollowing();
  67.     }
  68. }