diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 642830bbe743..6a77645787fb 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -131,8 +131,8 @@ public function withBroadcasting(string $channels, array $attributes = []) * Register the routing services for the application. * * @param \Closure|null $using - * @param string|null $web - * @param string|null $api + * @param array|string|null $web + * @param array|string|null $api * @param string|null $commands * @param string|null $channels * @param string|null $pages @@ -141,8 +141,8 @@ public function withBroadcasting(string $channels, array $attributes = []) * @return $this */ public function withRouting(?Closure $using = null, - ?string $web = null, - ?string $api = null, + array|string|null $web = null, + array|string|null $api = null, ?string $commands = null, ?string $channels = null, ?string $pages = null, @@ -150,7 +150,7 @@ public function withRouting(?Closure $using = null, string $apiPrefix = 'api', ?callable $then = null) { - if (is_null($using) && (is_string($web) || is_string($api) || is_string($pages) || is_string($health)) || is_callable($then)) { + if (is_null($using) && (is_string($web) || is_array($web) || is_string($api) || is_array($api) || is_string($pages) || is_string($health)) || is_callable($then)) { $using = $this->buildRoutingCallback($web, $api, $pages, $health, $apiPrefix, $then); } @@ -174,24 +174,32 @@ public function withRouting(?Closure $using = null, /** * Create the routing callback for the application. * - * @param string|null $web - * @param string|null $api + * @param array|string|null $web + * @param array|string|null $api * @param string|null $pages * @param string|null $health * @param string $apiPrefix * @param callable|null $then * @return \Closure */ - protected function buildRoutingCallback(?string $web, - ?string $api, + protected function buildRoutingCallback(array|string|null $web = null, + array|string|null $api = null, ?string $pages, ?string $health, string $apiPrefix, ?callable $then) { return function () use ($web, $api, $pages, $health, $apiPrefix, $then) { - if (is_string($api) && realpath($api) !== false) { - Route::middleware('api')->prefix($apiPrefix)->group($api); + if (is_string($api) || is_array($api)) { + if (is_array($api)) { + foreach ($api as $apiRoute) { + if (realpath($apiRoute) !== false) { + Route::middleware('api')->prefix($apiPrefix)->group($apiRoute); + } + } + } else { + Route::middleware('api')->prefix($apiPrefix)->group($api); + } } if (is_string($health)) { @@ -202,8 +210,16 @@ protected function buildRoutingCallback(?string $web, }); } - if (is_string($web) && realpath($web) !== false) { - Route::middleware('web')->group($web); + if (is_string($web) || is_array($web)) { + if (is_array($web)) { + foreach ($web as $webRoute) { + if (realpath($webRoute) !== false) { + Route::middleware('web')->group($webRoute); + } + } + } else { + Route::middleware('web')->group($web); + } } if (is_string($pages) &&