Replies: 1 comment 2 replies
-
Hi @AmirHkrg When However, when The practical takeaway is: use References: |
Beta Was this translation helpful? Give feedback.
-
Hi @AmirHkrg When However, when The practical takeaway is: use References: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
12
PHP Version
8.4
Database Driver & Version
No response
Description
Hello
I'm hoping to get some clarification on the intended behavior of
Route::can()->group()
. I've been exploring how it works and have a question based on my observations.I've noticed a difference in outcome when using
->can()
on a single route versus using it with a group.This code correctly triggers the Gate and blocks the request with a 403 response. This is clear and intuitive.
When using a group, the Gate does not seem to be triggered, and the
dd('pass')
statement is reached.To understand why this happens, I examined the cached route. I found that for the group scenario, instead of adding middleware directly, a
'can' => 'test'
attribute is added to the route's action array:My question stems from this observation. I've tried to trace how this 'can' attribute is converted into the Authorize middleware, but I haven't been able to find the relevant code in the framework's core. It seems to be set correctly in the action array, but I'm missing the step where it gets processed.
This leads to my main question:
Could you please point me to the part of the framework that is responsible for processing the 'can' action attribute and applying the middleware, specifically when it's defined via a route group?
I'm very curious to understand the underlying mechanism. I assume this functionality exists, but I'm unable to locate it. Why is this implemented via an action attribute rather than being directly added to the middleware stack, as one might initially expect?
Why do the
Route
facade andRouteRegistrar
provide acan()
method for grouping if its only effect is to add an action attribute that is never processed?I have tried
php artisan route:clear
to ensure I'm not seeing a cached result.Steps To Reproduce
Beta Was this translation helpful? Give feedback.
All reactions