Skip to content

Commit

Permalink
[11.x] Allow withMiddleware without callback in ApplicationBuilder …
Browse files Browse the repository at this point in the history
…class (#49982)
  • Loading branch information
buismaarten authored Feb 8, 2024
1 parent 0ac72f6 commit bad4256
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,18 @@ class_exists(Folio::class)) {
/**
* Register the global middleware, middleware groups, and middleware aliases for the application.
*
* @param callable $callback
* @param callable|null $callback
* @return $this
*/
public function withMiddleware(callable $callback)
public function withMiddleware(?callable $callback = null)
{
$this->app->afterResolving(HttpKernel::class, function ($kernel) use ($callback) {
$middleware = (new Middleware)
->redirectTo(fn () => route('login'));

$callback($middleware);
if (! is_null($callback)) {
$callback($middleware);
}

$this->pageMiddleware = $middleware->getPageMiddleware();
$kernel->setGlobalMiddleware($middleware->getGlobalMiddleware());
Expand Down

0 comments on commit bad4256

Please sign in to comment.