src/Security/UserVoter.php line 9
<?phpnamespace App\Security;use App\Entity\User;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter;class UserVoter extends Voter{public const DELETE = 'delete';public const EDIT = 'edit';public const SHOW = 'show';public const CREATE = 'create';/*** {@inheritdoc}*/protected function supports(string $attribute, $subject): bool{//dd($attribute, $subject);// this voter is only executed on User objects and for four specific permissionsreturn $subject instanceof User && \in_array($attribute, [self::SHOW, self::CREATE, self::EDIT, self::DELETE], true);}protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool{$user = $token->getUser();// the user must be logged in; if not, deny permissionif (!$user instanceof User) {return false;}if (\in_array(User::ROLE_ADMIN, $user->getRoles(), true)) {return true;} else {if (\in_array(User::ROLE_INSTRUCTOR, $user->getRoles(), true)) {return true;}}return ($user->getRoles() === $subject->getAuthor());}}