-
I have suggestion for writing route middlewares more beautiful and understandable. Example from docs where shown route defining with 'can' middleware: Route::post('/post', function () {
// The current user may create posts...
})->middleware('can:create,App\Post'); It is hard to read and model is not colorized and not clickable in IDE and code editors. How it implemented in other places: $user->can('create', Post::class) [2]: $this->authorize('create', Post::class); [3]: @can('create', App\Post::class)
<!-- The Current User Can Create Posts -->
@endcan Then, if this ability will be implemented for route middlewares, it could look better like this: Route::post('/post', function () {
// The current user may create posts...
})->middleware(Can::ability('create', \App\Post::class)); or like this: Route::post('/post', function () {
// The current user may create posts...
})->middleware(Authorize::ability('create')->parameters(\App\Post::class)); or... something else. Route middlewares dont support objects now, only strings. And middleware class maybe referenced the only way: Route::post('/post', function () {
// The current user may create posts...
})->middleware(Authorize::class); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
UPD: Something like this suggestion implemented by @timacdonald More detail here: https://timacdonald.me/rethinking-laravels-middleware-argument-api |
Beta Was this translation helpful? Give feedback.
UPD: Something like this suggestion implemented by @timacdonald
More detail here: https://timacdonald.me/rethinking-laravels-middleware-argument-api