Advertisement
Guest User

Untitled

a guest
May 13th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Entity;
  4.  
  5. use App\Repository\GroupRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9.  
  10. #[ORM\Entity(repositoryClass: GroupRepository::class)]
  11. #[ORM\Table(name: '`group`')]
  12. class Group
  13. {
  14.     #[ORM\Id]
  15.    #[ORM\GeneratedValue]
  16.    #[ORM\Column]
  17.    private ?int $id = null;
  18.  
  19.     #[ORM\Column(length: 255)]
  20.    private ?string $name = null;
  21.  
  22.     /**
  23.      * @var Collection<int, User>
  24.      */
  25.     #[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'groups')]
  26.    private Collection $users;
  27.  
  28.     public function __construct()
  29.     {
  30.         $this->users = new ArrayCollection();
  31.     }
  32.  
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.  
  38.     public function getName(): ?string
  39.     {
  40.         return $this->name;
  41.     }
  42.  
  43.     public function setName(string $name): static
  44.     {
  45.         $this->name = $name;
  46.  
  47.         return $this;
  48.     }
  49.  
  50.     /**
  51.      * @return Collection<int, User>
  52.      */
  53.     public function getUsers(): Collection
  54.     {
  55.         return $this->users;
  56.     }
  57.  
  58.     public function addUser(User $user): static
  59.     {
  60.         if (!$this->users->contains($user)) {
  61.             $this->users->add($user);
  62.         }
  63.  
  64.         return $this;
  65.     }
  66.  
  67.     public function removeUser(User $user): static
  68.     {
  69.         $this->users->removeElement($user);
  70.  
  71.         return $this;
  72.     }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement