Laravel的路由命名空间 发表于 2018-03-08 更新于 2018-03-27 ... 一般用法123Route::namespace('Admin')->group(function () { // 在 "App\Http\Controllers\Admin" 命名空间下的控制器}); 进阶用法如果我们的类不在App\Http\Controllers下, 要使用namespace, 就要修改一些东西修改文件App\Providers\RouteServiceProvider 12345678910111213141516171819202122class 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'; protected $apiNamespace = 'App\Http'; ...... protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->apiNamespace) ->group(base_path('routes/api.php')); } 使用 12345678Route::namespace('Api')->group(function () { Route::post('/order/update', 'Order@receive')->name('api.order.receive'); Route::post('/order/delete', 'Order@delete')->name('api.order.delete'); Route::get('/fetch-waybill', 'FetchWaybill@getNotFetchTask')->name('api.fetch-waybill.get'); Route::post('fetch-waybill/callback', 'FetchWaybill@callback')->name('api.fetch-waybill.callback');});