| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Providers;
- use Illuminate\Cache\RateLimiting\Limit;
- use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\RateLimiter;
- use Illuminate\Support\Facades\Route;
- class RouteServiceProvider extends ServiceProvider
- {
- /**
- * The path to the "home" route for your application.
- *
- * This is used by Laravel authentication to redirect users after login.
- *
- * @var string
- */
- public const HOME = '/home';
- /**
- * The controller namespace for the application.
- *
- * When present, controller route declarations will automatically be prefixed with this namespace.
- *
- * @var string|null
- */
- protected $namespace = 'App\\Http\\Controllers';
- /**
- * Define your route model bindings, pattern filters, etc.
- *
- * @return void
- */
- public function boot()
- {
- $this->configureRateLimiting();
- $this->mapApiRoutes();
- $this->mapAdminApiRoutes();
- $this->routes(function () {
- Route::middleware('web')
- ->namespace($this->namespace)
- ->group(base_path('routes/web.php'));
- });
- }
- /**
- * Configure the rate limiters for the application.
- *
- * @return void
- */
- protected function configureRateLimiting()
- {
- RateLimiter::for('api', function (Request $request) {
- return Limit::perMinute(60);
- });
- }
- protected function mapApiRoutes()
- {
- Route::prefix('api')
- ->middleware('api')
- ->namespace($this->namespace)
- ->group(base_path('routes/api.php'));
- //dd($this->namespace);
- foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
- $fileName = basename( $fileName );
- Route::middleware('api_verify')
- ->namespace( $this->namespace."\\Api" )
- ->prefix('api')
- ->group( base_path('routes'.DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR."{$fileName}") );
- }
- }
- /**
- * 总后台API路由
- */
- protected function mapAdminApiRoutes(){
- foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'adminApi'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
- $fileName = basename( $fileName );
- //中间件过滤加载
- Route::middleware('adminApiVerify')
- ->namespace( $this->namespace."\\AdminApi" )
- ->prefix('adminApi')
- ->group( base_path('routes'.DIRECTORY_SEPARATOR.'adminApi'.DIRECTORY_SEPARATOR."{$fileName}") );
- }
- }
- }
|