dartmoon / laravel-route-helpers
Set of helper for the Route facade
v1.0.0
2023-05-16 16:06 UTC
Requires (Dev)
- orchestra/testbench: ^7.24
- pestphp/pest: ^1.23
- pestphp/pest-plugin-laravel: ^1.4
- pestphp/pest-plugin-parallel: ^1.2
README
Add a simple Route::when macro to conditionally register routes.
Installation
composer require dartmoon/laravel-route-helpers
Usage
When the condition is true the route will be registered, otherwise it will be ignored.
Route::when($condition, function () { Route::get('/registered/only/when/condition/is/true', fn () => 'Hello World'); });
For example you can register routes base on app locale.
Route::when(app()->getLocale() == 'en', function () { Route::get('about', fn () => 'English'); }); Route::when(app()->getLocale() == 'it', function () { Route::get('about', fn () => 'Italiano'); });
License
This project is licensed under the MIT License - see the LICENSE.md file for details