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 accessing the premium content.
Route CachingLaravel can cache your routes to make it quicker to find the code to run. Just run the command php artisan route:cache . The problem you might find with this is that you can now cache route closures therefore you will need to change any closures to call methods on controllers.
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.
This does the trick:
Route::any('/{any}', 'MyController@myMethod')->where('any', '.*');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With