RouteServiceProvider.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\Facades\Route;
  4. use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  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. * 全局约束路由参数id
  24. * add by pjh 20180420
  25. */
  26. Route::pattern('id', '[0-9]+');
  27. parent::boot();
  28. }
  29. /**
  30. * Define the routes for the application.
  31. *
  32. * @return void
  33. */
  34. public function map()
  35. {
  36. $this->mapApiRoutes();
  37. $this->mapWebRoutes();
  38. //
  39. }
  40. /**
  41. * Define the "web" routes for the application.
  42. *
  43. * These routes all receive session state, CSRF protection, etc.
  44. *
  45. * @return void
  46. */
  47. protected function mapWebRoutes()
  48. {
  49. Route::middleware('web')
  50. ->namespace($this->namespace)
  51. ->group(base_path('routes/web.php'));
  52. }
  53. /**
  54. * Define the "api" routes for the application.
  55. *
  56. * These routes are typically stateless.
  57. *
  58. * @return void
  59. */
  60. protected function mapApiRoutes()
  61. {
  62. Route::prefix('api')
  63. ->middleware('api')
  64. ->namespace($this->namespace)
  65. ->group(base_path('routes/api.php'));
  66. }
  67. }