Replies: 2 comments 1 reply
-
Hi there 👋 If you're typically just using an action as a controller, you may simply define the authorisation logic inside the public function authorize(): bool
{
return Gate::allows('viewAny', Note::class);
} or if you prefer to be explicit with the user to authorise. public function authorize(ActionRequest $request): bool
{
return Gate::forUser($request->user())->allows('viewAny', Note::class);
} However, if you want this authorisation logic to trigger no matter how you call your actions (e.g. as an object using public function handle()
{
Gate::authorize('viewAny', Note::class);
// ...
} I hope this helps. 🙂 |
Beta Was this translation helpful? Give feedback.
-
Hi, I am comming from v1. What would be is the best practice about get logged user on v2? Typically on v1 v1 public function handle(){
$var = Tournament::isManagedBy($this->user()));
// more logic using $var
} |
Beta Was this translation helpful? Give feedback.
-
Hello @lorisleiva 👋
can you shed some light on how to authorize actions?
From a controller or even a livewire component I am used to do:
Using actions:
Refactoring the authorization into the action:
Are you using a similar approach or are you recommending another way?
Beta Was this translation helpful? Give feedback.
All reactions