Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit def74b9

Browse files
author
Alex Giuvara
committed
Add Laravel 5.4 api and web routes
1 parent e31dd8b commit def74b9

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

src/Providers/RouteServiceProvider.php

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,74 @@
22

33
namespace Lucid\Foundation\Providers;
44

5-
use Illuminate\Routing\Router;
65
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as BaseServiceProvider;
6+
use Illuminate\Routing\Router;
77

88
abstract class RouteServiceProvider extends BaseServiceProvider
99
{
1010
/**
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
1212
*
1313
* @param \Illuminate\Routing\Router $router
1414
*/
1515
abstract public function map(Router $router);
1616

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)
1867
{
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;
2373
});
2474
}
2575
}

0 commit comments

Comments
 (0)