How do I make a Catch-All Route in Laravel

后端 未结 4 1955
悲哀的现实
悲哀的现实 2020-12-05 13:01

I need a laravel routes.php entry that will catch all traffic to a specific domain.com/premium-section of the site so that I can prompt people to become members before acces

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 13:41

    You could also catch 'all' by using a regex on the parameter.

    Route::group(['prefix' => 'premium-section'], function () {
        // other routes
        ...
        Route::get('{any}', function ($any) {
            ...
        })->where('any', '.*');
    });
    

    Also can catch the whole group if no routes are defined with an optional param.

    Route::get('{any?}', function ($any = null) {
        ...
    })->where('any', '.*');
    

    This last one would catch 'domain.com/premium-section' as well.

提交回复
热议问题