-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Middleware except #9
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add some docs around this new feature to the README, @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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
->withMiddleware(function (Middleware $middleware) { | ||
$middleware->web(append: [ | ||
- \Pirsch\Http\Middleware\TrackPageview::class, | ||
+ \App\Http\Middleware\TrackPageview::class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless the middleware is published your name space should probably remain \Pirsch\Http\Middleware\TrackPageview
.
And one other small note is that this registration I think will only work with Laravel 11.
Laravel 10 and below would be in \App\Http\Kernel
You may need to bump the composer.json minimum framework version requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless the middleware is published your name space should probably remain
No, this is your local file created just below, see line 116.
@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);
} |
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
TrustProxies
middleware.This allows you to extends
TrackPageview
middleware like: