Improve Middleware except#9
Conversation
|
@zepfietje thank you! and done. |
|
Mine offered a way to block other headers by using https://github.com/pirsch-analytics/laravel-pirsch/pull/3/files |
|
What isn't achievable with this implementation that was possible with yours, @adampatterson? |
|
@zepfietje It's probably fine, I can't think of any other existing Laravel packages that I'd want to exclude but I went with the config approach just in case there were other routes that should be ignored. I don't know why you would add Pirsch to web hook group but you could for instance exclude the Cashier route by modifying the config. Maybe to track events |
|
This PR still allows for complete configuration of excluded routes, right @asbiin? |
|
That's how I'm reading the code, the excluded headers and routes are in protected methods. I think it would be possible to add a param to By the way, I like the idea of excluding headers, and the param might be a nice touch. https://laravel.com/docs/11.x/middleware#middleware-parameters |
|
@adampatterson it doesn't matter that they're protected, since you're extending the base middleware class and overriding those properties. |
I like the idea. |
|
Sure, go ahead and create another PR so we can compare before merging one of them, @asbiin. |
Well, I'm done with this PR here. I expected @adampatterson to create another base on his proposal? |
|
I can do that, I think after this one is merged in. |
|
Ideally I'd review the two approaches and only merge the one that we think is best. |
|
@zepfietje @adampatterson I had a more close lock at the Please review the I also fixed the tests which wasn't accurate ! I hope this will help you ... |
|
Shouldn't it be possible when using |
You can see in the documentation:
So the parameters are strings separated by commas. |
|
Alright, I think I don't like this approach to exclude URLs then. |
adampatterson
left a comment
There was a problem hiding this comment.
The middleware name space may not be correctly documented. This is also a Laravel 11 specific configuration.
We may want to include an example for previous versions.
|
@asbiin I haven't tried this, but Chat GPT showed basically what you have except they didn't typecast with string. I wonder if adding public function handle($request, Closure $next, ...$roles)
{
// $roles is an array of the provided parameters
if (!in_array($request->user()->role, $roles)) {
// Redirect or return a response if the role doesn't match
return redirect('home');
}
return $next($request);
} |
|
@adampatterson would you (re)consider merging this one please? |
This is inspired by https://github.com/laravel/framework/blob/master/src/Illuminate/Foundation/Http/Middleware/Concerns/ExcludesPaths.php trait (from Laravel 11.x) used in
TrustProxiesmiddleware.This allows you to extends
TrackPageviewmiddleware like: