如何在拉拉维尔制作一条包罗万象的路线
我需要一个Laravel条目,该条目将捕获特定网站的所有流量,以便我可以在访问高级内容之前提示人们成为会员。routes.php
example.com/premium-section
我需要一个Laravel条目,该条目将捕获特定网站的所有流量,以便我可以在访问高级内容之前提示人们成为会员。routes.php
example.com/premium-section
您还可以通过在参数上使用正则表达式来捕获“all”。
Route::group(['prefix' => 'premium-section'], function () {
// other routes
...
Route::get('{any}', function ($any) {
...
})->where('any', '.*');
});
如果没有使用可选参数定义路由,也可以捕获整个组。
Route::get('{any?}', function ($any = null) {
...
})->where('any', '.*');
最后一个也会抓住。example.com/premium-section
这就完成了以下操作:
Route::any('/{any}', 'MyController@myMethod')->where('any', '.*');