請我有一點源我們是幾個 fulstack 開發人員,我們使用 git 我希望每個人都有他們的路由檔案,例如 web1.php 和 web2.php 然后使用 require 函式集成到檔案 laravel routes / web.php 但是這是行不通的
uj5u.com熱心網友回復:
您可以通過為每個路由檔案使用不同的中間件來擁有多個路由檔案。在路由檔案夾中創建路由檔案后,您應該像這樣將檔案添加到 boot() 函式中的 RouteServiceProvider.php。
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('user_prefix')
->middleware('user_middleware')
->namespace($this->namespace)
->group(base_path('routes/userroute.php'));
});
}
然后停止服務器,如果它正在運行并運行
php工匠配置:清除
然后重新啟動您的服務器。
uj5u.com熱心網友回復:
如果你想要單獨的route檔案,你可以這樣做
專案樹
|-- Project
|-- ...
|-- routes
|-- other
|-- other_route.php
|-- web.php
將您的其他路線檔案包含在 web.php
// web.php
Route::prefix('other')->name('other.')->group(__DIR__ . '/other/other_route.php');
...
// other_route.php
Route::get('/', [SomeController::class, 'index']);
...
如果您使用artisan,請運行php artisan route:list以檢查已注冊的路線
它適用于api.php和web.php。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/407375.html
標籤:
