RouteServiceProvider.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  4. use Illuminate\Support\Facades\Route;
  5. class RouteServiceProvider extends ServiceProvider
  6. {
  7. /**
  8. * This namespace is applied to your controller routes.
  9. *
  10. * In addition, it is set as the URL generator's root namespace.
  11. *
  12. * @var string
  13. */
  14. protected $namespace = 'App\Http\Controllers';
  15. /**
  16. * Define your route model bindings, pattern filters, etc.
  17. *
  18. * @return void
  19. */
  20. public function boot()
  21. {
  22. //
  23. parent::boot();
  24. }
  25. /**
  26. * Define the routes for the application.
  27. *
  28. * @return void
  29. */
  30. public function map()
  31. {
  32. $this->mapApiRoutes();
  33. $this->mapWebRoutes();
  34. //
  35. }
  36. /**
  37. * Define the "web" routes for the application.
  38. *
  39. * These routes all receive session state, CSRF protection, etc.
  40. *
  41. * @return void
  42. */
  43. protected function mapWebRoutes()
  44. {
  45. Route::middleware('web')
  46. ->namespace($this->namespace)
  47. ->group(base_path('routes/web.php'));
  48. }
  49. /**
  50. * Define the "api" routes for the application.
  51. *
  52. * These routes are typically stateless.
  53. *
  54. * @return void
  55. */
  56. protected function mapApiRoutes()
  57. {
  58. Route::group([
  59. 'prefix' => '/api/v1',
  60. 'middleware' => 'api',
  61. 'namespace' => $this->namespace
  62. ], function ($router) {
  63. foreach (glob(app_path('Http//Routes') . '/*.php') as $file) {
  64. $this->app->make('App\\Http\\Routes\\' . basename($file, '.php'))->map($router);
  65. }
  66. });
  67. }
  68. }