route-attributes.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. $return = [
  3. /*
  4. * Automatic registration of routes will only happen if this setting is `true`
  5. */
  6. 'enabled' => true,
  7. /*
  8. * Controllers in these directories that have routing attributes
  9. * will automatically be registered.
  10. *
  11. * Optionally, you can specify group configuration by using key/values
  12. */
  13. 'directories' => [
  14. app_path('Http/Controllers'),
  15. // app_path('Module/User/Controllers') => [
  16. // 'prefix' => 'admin',
  17. // 'middleware' => 'admin',
  18. // // only register routes in files that match the patterns
  19. // 'patterns' => ['*Controller.php'],
  20. // // do not register routes in files that match the patterns
  21. // 'not_patterns' => [],
  22. // ],
  23. ],
  24. /*
  25. * This middleware will be applied to all routes.
  26. */
  27. 'middleware' => [
  28. \Illuminate\Routing\Middleware\SubstituteBindings::class
  29. ],
  30. /*
  31. * When enabled, implicitly scoped bindings will be enabled by default.
  32. * You can override this behaviour by using the `ScopeBindings` attribute, and passing `false` to it.
  33. *
  34. * Possible values:
  35. * - null: use the default behaviour
  36. * - true: enable implicitly scoped bindings for all routes
  37. * - false: disable implicitly scoped bindings for all routes
  38. */
  39. 'scope-bindings' => null,
  40. ];
  41. $modulePath = app_path('Module');
  42. $files = scandir($modulePath);
  43. $Modules = [];
  44. foreach ($files as $file) {
  45. if ($file !== '.' && $file !== '..') { // 排除当前目录和上级目录
  46. if (is_dir($modulePath . '/' . $file)) {
  47. $Modules[] = $file;
  48. }
  49. }
  50. }
  51. foreach ($Modules as $key => $module) {
  52. if (is_dir($modulePath . '/' . $module . '/AdminControllers')) {
  53. // 后台路由
  54. $return['directories'][app_path('Module/' . $module . '/AdminControllers')] = [
  55. 'prefix' => config('admin.route.prefix'),
  56. 'middleware' => config('admin.route.middleware'),
  57. // only register routes in files that match the patterns
  58. 'patterns' => ['*Controller.php'],
  59. // do not register routes in files that match the patterns
  60. 'not_patterns' => [],
  61. ];
  62. }
  63. if (is_dir($modulePath . '/' . $module . '/Controllers')) {
  64. // 前台路由,2025-04-02 没用到
  65. $return['directories'][app_path('Module/' . $module . '/Controllers')] = [
  66. 'prefix' => 'api',
  67. 'middleware' => ['web'],
  68. // only register routes in files that match the patterns
  69. 'patterns' => ['*Controller.php'],
  70. // do not register routes in files that match the patterns
  71. 'not_patterns' => [],
  72. ];
  73. }
  74. }
  75. return $return;