學習參考文章 https://learnku.com/articles/13622/the-principle-of-laravel-routing-execution
<?php
namespace app\common\providers;
use app\common\services\Check;
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. 定義當前 Laravel 應用控制器路由的命名空間。
*/
protected $namespace = 'app';
/**
* Define your route model bindings, pattern filters, etc. 定義路由綁定、正則過濾等。
*/
public function boot()
{
parent::boot();
}
/**
* Define the routes for the application. 定義應用的路由。
*/
public function map()
{
if (env('APP_Framework') == 'platform') {
$this->mapWebBootRoutes();
$this->mapPlatformRoutes();
$this->mapShopRoutes();
$this->mapApiRoutes();
} else {
$this->mapWebRoutes();
}
}
/**
* Define the "web" routes for the application. 定義應用 Web 路由。
*
* These routes all receive session state, CSRF protection, etc. 這里定義的所有路由都會處理會話狀態和 CSRF 防護等處理。
*/
protected function mapWebRoutes()
{
Route::group([
'middleware' => ['web'],
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/web.php');
});
}
protected function mapWebBootRoutes()
{
Route::group([
'prefix' => 'api',
'middleware' => ['web'],
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/boot.php');
});
}
/**
* 前端路由
*
*/
protected function mapApiRoutes()
{
Route::group([
'middleware' => ['web'],
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/api.php');
});
}
/**
* 框架路由
*
*/
protected function mapPlatformRoutes()
{
Route::group([
'prefix' => 'admin',
'middleware' => ['admin'],
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/admin.php');
});
}
/**
* 商城路由
*
*/
protected function mapShopRoutes()
{
Route::group([
'prefix' => 'admin',
'middleware' => ['admin'],
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/shop.php');
});
}
}
查看商城首頁鏈接: http://yunzhong.gysr.top/addons/yun_shop/?menu=#/home?i=2 前端商城用的vue框架
路由分發
這一節我們主要講解 HTTP 如何被分發到相關路由並執行路由設置的回調(或控制器)。
如果你有了解過 Laravel 生命周期的話,應該知道所有的 HTTP 請求都是由 Illuminate\Foundation\Http\kernel::class內核處理的,而捕獲 HTTP 請求操作位於項目的入口文件 public/index.php 中。
前端頁面api 地址: http://yunzhong.gysr.top/addons/yun_shop/api.php?i=2&uuid=0&type=1&shop_id=null&route=home-page.index&