|
2 | 2 |
|
3 | 3 | namespace Lucid\Foundation\Providers;
|
4 | 4 |
|
5 |
| -use Illuminate\Routing\Router; |
6 | 5 | use Illuminate\Foundation\Support\Providers\RouteServiceProvider as BaseServiceProvider;
|
| 6 | +use Illuminate\Routing\Router; |
7 | 7 |
|
8 | 8 | abstract class RouteServiceProvider extends BaseServiceProvider
|
9 | 9 | {
|
10 | 10 | /**
|
11 |
| - * Read the routes from the "routes.php" file of this Service |
| 11 | + * Read the routes from the "api.php" and "web.php" files of this Service |
12 | 12 | *
|
13 | 13 | * @param \Illuminate\Routing\Router $router
|
14 | 14 | */
|
15 | 15 | abstract public function map(Router $router);
|
16 | 16 |
|
17 |
| - public function loadRoutesFile($router, $namespace, $path) |
| 17 | + /** |
| 18 | + * @param $router |
| 19 | + * @param $namespace |
| 20 | + * @param $pathApi |
| 21 | + * @param $pathWeb |
| 22 | + */ |
| 23 | + public function loadRoutesFiles($router, $namespace, $pathApi = null, $pathWeb = null) |
| 24 | + { |
| 25 | + if (is_file($pathApi)) { |
| 26 | + $this->mapApiRoutes($router, $namespace, $pathApi); |
| 27 | + } |
| 28 | + if (is_file($pathWeb)) { |
| 29 | + $this->mapWebRoutes($router, $namespace, $pathWeb); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Define the "api" routes for the application. |
| 35 | + * |
| 36 | + * These routes are typically stateless. |
| 37 | + * |
| 38 | + * @param $router |
| 39 | + * @param $namespace |
| 40 | + * @param $path |
| 41 | + * |
| 42 | + * @return void |
| 43 | + */ |
| 44 | + protected function mapApiRoutes($router, $namespace, $path) |
| 45 | + { |
| 46 | + $router->group([ |
| 47 | + 'middleware' => 'api', |
| 48 | + 'namespace' => $namespace, |
| 49 | + 'prefix' => 'api' |
| 50 | + ], function ($router) use ($path) { |
| 51 | + require $path; |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Define the "web" routes for the application. |
| 57 | + * |
| 58 | + * These routes all receive session state, CSRF protection, etc. |
| 59 | + * |
| 60 | + * @param $router |
| 61 | + * @param $namespace |
| 62 | + * @param $path |
| 63 | + * |
| 64 | + * @return void |
| 65 | + */ |
| 66 | + protected function mapWebRoutes($router, $namespace, $path) |
18 | 67 | {
|
19 |
| - $router->group(['namespace' => $namespace], function ($router) use ($path) { |
20 |
| - if (file_exists($path)) { |
21 |
| - require $path; |
22 |
| - } |
| 68 | + $router->group([ |
| 69 | + 'middleware' => 'web', |
| 70 | + 'namespace' => $namespace |
| 71 | + ], function ($router) use ($path) { |
| 72 | + require $path; |
23 | 73 | });
|
24 | 74 | }
|
25 | 75 | }
|
0 commit comments