123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace App\Providers;
- use Illuminate\Support\Facades\Route;
- use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
- class RouteServiceProvider extends ServiceProvider
- {
- /**
- * This namespace is applied to your controller routes.
- *
- * In addition, it is set as the URL generator's root namespace.
- *
- * @var string
- */
- protected $namespace = 'App\Http\Controllers';
- /**
- * Define your route model bindings, pattern filters, etc.
- *
- * @return void
- */
- public function boot()
- {
- //
- parent::boot();
- }
- /**
- * Define the routes for the application.
- *
- * @return void
- */
- public function map()
- {
- $this->mapApiRoutes();
- $this->mapShopApiRoutes();
- $this->mapWapRoutes();
- $this->mapWebRoutes();
- $this->mapWebsRoutes();
- //
- $this->mapAdminApiRoutes();
- }
- /**
- * Define the "web" routes for the application.
- *
- * These routes all receive session state, CSRF protection, etc.
- *
- * @return void
- */
- protected function mapWebRoutes()
- {
- Route::middleware('web')
- ->namespace($this->namespace)
- ->group(base_path('routes/web.php'));
- }
- /**
- * Define the "api" routes for the application.
- *
- * These routes are typically stateless.
- *
- * @return void
- */
- protected function mapApiRoutes()
- {
- Route::prefix('api')
- ->middleware('api')
- ->namespace($this->namespace)
- ->group(base_path('routes/api.php'));
- 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 mapShopApiRoutes(){
- foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'shopApi'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
- $fileName = basename( $fileName );
- Route::middleware('shop_verify')
- ->namespace( $this->namespace."\\ShopApi" )
- ->prefix('shopApi')
- ->group( base_path('routes'.DIRECTORY_SEPARATOR.'shopApi'.DIRECTORY_SEPARATOR."{$fileName}") );
- }
- }
- /**
- * Wap端
- */
- protected function mapWapRoutes()
- {
- foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'wap'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
- $fileName = basename( $fileName );
- Route::middleware('wap_verify')
- ->namespace( $this->namespace."\\Wap" )
- ->group( base_path('routes'.DIRECTORY_SEPARATOR.'wap'.DIRECTORY_SEPARATOR."{$fileName}") );
- }
- }
- /**
- * web 路由规则
- * @return void
- */
- protected function mapWebsRoutes(){
- foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'web'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
- $fileName = basename( $fileName );
- $prefix = substr( $fileName,0,strrpos($fileName,'.') );
- $nameSpace = ucfirst($prefix);
- //中间件过滤加载
- Route::middleware('web','admin_verify')
- ->namespace( $this->namespace."\\{$nameSpace}" )
- ->group( base_path('routes'.DIRECTORY_SEPARATOR.'web'.DIRECTORY_SEPARATOR."{$fileName}") );
- }
- }
- /**
- * 总后台API路由
- */
- protected function mapAdminApiRoutes(){
- foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'adminApi'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
- $fileName = basename( $fileName );
- $prefix = substr( $fileName,0,strrpos($fileName,'.') );
- $nameSpace = ucfirst($prefix);
- //中间件过滤加载
- Route::middleware('adminApi_verify')
- ->namespace( $this->namespace."\\AdminApi" )
- ->group( base_path('routes'.DIRECTORY_SEPARATOR.'adminApi'.DIRECTORY_SEPARATOR."{$fileName}") );
- }
- }
- }
|