Skip to content

Add $middleware->insertBefore() and $middleware->insertAfter() helper methods - #62261

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
ziadoz:middleware-insert-before-after
Oct 30, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
ziadoz:middleware-insert-before-after

Conversation

@ziadoz

@ziadoz ziadoz commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This builds on the small changes to $middleware->replace() I made the other day: #62230

It adds a few shortcut methods to make it easy to add middleware to the stack before or after Laravel's built-in ones:

->withMiddleware(function (Middleware $middleware) {
    // Run after built-in TrustProxies...
    $middleware->insertAfter(TrustProxies::class, StripCrossOriginReferer::class);
    
    // Run before built-in TrimStrings...
    $middleware->insertBefore(TrimStrings::class, SanitiseStrings::class);
});

@github-actions

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@ziadoz
ziadoz marked this pull request as ready for review October 30, 2026 12:30
@taylorotwell
taylorotwell merged commit feab8b1 into laravel:13.x Oct 30, 2026
64 checks passed
@ziadoz
ziadoz deleted the middleware-insert-before-after branch October 30, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants