Answer the question
In order to leave comments, you need to log in
Checking user actions directly in controller method?
Colleagues, good night!
Is there a practice of checking permissions in a controller method?
Me about it:
Method in controller
public function delete()
{
$this->checkPermission($this->getRole('email'), Action::DELETE); // Проверка
...
}
Answer the question
In order to leave comments, you need to log in
The trait is redundant here, use DI. Yes, you can check permissions in the controller, as symphony does, for example.
Make new methods to make your life easier:
public function checkDeletePermission($role) {
$this->checkPermission($this->getRole($role), Action::DELETE);
}
public function checkReadPermission($role) {
$this->checkPermission($this->getRole($role), Action::READ);
}
public function checkCreatePermission($role) {
$this->checkPermission($this->getRole($role), Action::CREATE);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question