src/Entity/Roles.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RolesRepository;
  4. use App\Traits\CommonTrt;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=RolesRepository::class)
  10.  */
  11. class Roles
  12. {
  13.     use CommonTrt;
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      */
  23.     private $name;
  24.     /**
  25.      * @ORM\Column(type="string", length=255)
  26.      */
  27.     private $slug;
  28.     /**
  29.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="userRoles")
  30.      */
  31.     private $users;
  32.     public function __construct()
  33.     {
  34.         $this->users = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getName(): ?string
  41.     {
  42.         return $this->name;
  43.     }
  44.     public function setName(string $name): self
  45.     {
  46.         $this->name = $name;
  47.         return $this;
  48.     }
  49.     public function getSlug(): ?string
  50.     {
  51.         return $this->slug;
  52.     }
  53.     public function setSlug(string $slug): self
  54.     {
  55.         $this->slug = $slug;
  56.         return $this;
  57.     }
  58.     /**
  59.      * @return Collection<int, User>
  60.      */
  61.     public function getUsers(): Collection
  62.     {
  63.         return $this->users;
  64.     }
  65.     public function addUser(User $user): self
  66.     {
  67.         if (!$this->users->contains($user)) {
  68.             $this->users[] = $user;
  69.             $user->addUserRole($this);
  70.         }
  71.         return $this;
  72.     }
  73.     public function removeUser(User $user): self
  74.     {
  75.         if ($this->users->removeElement($user)) {
  76.             $user->removeUserRole($this);
  77.         }
  78.         return $this;
  79.     }
  80. }