Skip to content

Commit 4c4a800

Browse files
author
rokde
committed
routes support changed
1 parent 096f244 commit 4c4a800

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ class YOURPACKAGEServiceProvider extends PackageServiceProvider implements Defin
103103
Add your routes source path:
104104
```php
105105
/**
106-
* returns routes.php file (absolute path)
106+
* returns routes/web.php|... files (absolute paths)
107107
*
108-
* @return string
108+
* @return array|string[]
109109
*/
110-
public function routesFile()
110+
public function routesFiles()
111111
{
112-
return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'web.php';
112+
return [
113+
__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'web.php'
114+
];
113115
}
114116
```
115117

src/PackageServiceProvider.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ abstract protected function namespace();
3838
public function boot()
3939
{
4040
if ( ! $this->app->routesAreCached()) {
41+
/** @var \Illuminate\Routing\Router $router */
42+
$router = $this->app->make(\Illuminate\Routing\Router::class);
43+
4144
if ($this instanceof DefinesRoutes) {
42-
$routesFile = $this->routesFile();
43-
require $routesFile;
45+
$routesFiles = $this->routesFiles();
46+
foreach ((array)$routesFiles as $routesFile) {
47+
// $router exists
48+
if (file_exists($routesFile)) {
49+
require $routesFile;
50+
}
51+
}
4452
}
4553
if ($this instanceof DefinesRouteRegistrar) {
46-
/** @var \Illuminate\Routing\Router $router */
47-
$router = $this->app->make(\Illuminate\Routing\Router::class);
48-
4954
$this->registerRoutesWithRouter($router);
5055
}
5156
}

src/Support/DefinesRoutes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface DefinesRoutes
77
/**
88
* returns routes.php file (absolute path)
99
*
10-
* @return string
10+
* @return array|string[]
1111
*/
12-
public function routesFile();
12+
public function routesFiles();
1313
}

0 commit comments

Comments
 (0)