在 Laravel 中添加一条路线作为最后一条路线,来自作曲家模块?
Adding a route in Laravel as the last route, from a composer module?
我正在为 Laravel 制作一个模块,为了便于重用,我将其作为一个单独的作曲家模块制作。
在这个模块中,我必须定义一个包罗万象的路由,但我不希望它覆盖项目中任何手动添加的路由。
有谁知道我如何获得这种行为?
我正在像这样在 ServiceProviders boot() 方法中注册我的路由:
public function boot()
{
$this->loadMigrationsFrom(__DIR__.'/migrations');
$this->loadRoutesFrom(__DIR__.'/routes/routes.php');
}
而routes.php也很简单:
$regex = ".*";
Route::namespace('Asator\Runepost\Controllers')
->middleware(['web', DynamicContent::class])
->group(function($route) use ($regex) {
$route->any('{any}', 'RunepostFrontController')->where('any', $regex);
});
在手动添加的路由有 运行 之后,是否可以以某种方式将路由添加为最后一条路由?
只需在 config/app.php 中添加模块的 ServiceProvider after App 的 RouteServiceProvider 并确保你的 catch-all-route 是你模块的路由。
我正在为 Laravel 制作一个模块,为了便于重用,我将其作为一个单独的作曲家模块制作。
在这个模块中,我必须定义一个包罗万象的路由,但我不希望它覆盖项目中任何手动添加的路由。
有谁知道我如何获得这种行为?
我正在像这样在 ServiceProviders boot() 方法中注册我的路由:
public function boot()
{
$this->loadMigrationsFrom(__DIR__.'/migrations');
$this->loadRoutesFrom(__DIR__.'/routes/routes.php');
}
而routes.php也很简单:
$regex = ".*";
Route::namespace('Asator\Runepost\Controllers')
->middleware(['web', DynamicContent::class])
->group(function($route) use ($regex) {
$route->any('{any}', 'RunepostFrontController')->where('any', $regex);
});
在手动添加的路由有 运行 之后,是否可以以某种方式将路由添加为最后一条路由?
只需在 config/app.php 中添加模块的 ServiceProvider after App 的 RouteServiceProvider 并确保你的 catch-all-route 是你模块的路由。