New Route::resource()->authorize(Model::class) #45396
Unanswered
khalyomede
asked this question in
Ideas
Replies: 1 comment
-
Seems like, we could just simply use the existing authorizing resource call. Sounds like a win, but it would lack ability to customize it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, only
Route::{get,post,put,patch,delete}()
allows to chain->can("verb", Model::class)
after it.To authorize resources, we have to call the "can" middleware (or
Route::group(["middleware" => "..."])
) by hand, and the syntax is less handy because it does not understand the second parameter as the model:I propose to create a shorthand
->authorize()
, since policies are generated with all the necessary common methods to validate CRUD action on a model, allowing to reduce all the code above to:This would find the policy(ies) attached to this model and validate each actions according to the route resource in this fashion:
PostPolicy::viewAny()
PostPolicy::view()
PostPolicy::create()
PostPolicy::create()
PostPolicy::update()
PostPolicy::update()
PostPolicy::delete()
We could, in the same manner as we can customize
Route::resource()
, offer the user to switch to sport mode and tell exactly how to resolves routes VS policies:And we can allow to only override what should be manually resolved, keeping the rest automatically resolved:
Beta Was this translation helpful? Give feedback.
All reactions