[Proposal] Add route priority
I have been working on package which has a routes file and loads a number of routes, including a slug based route which really needs to be loaded last in the route order to catch anything which hasn't been matched. Here is the route
Route::match(array('GET', 'POST'), '{slug}', function($slug)
{
// Handle the route
})->where('slug', '[\/_\-\_A-Za-z0-9]+');
This actually works fine, but because the package is loaded before the app/routes.php file it means that if the user wants to load anything in their own routes file then it will not be found because my 'catch all' route is already matching and returning a 404 if it doesn't match a slug in the database.
I could get around this by offering users the option to not load routes automatically and instead add a method call in their own routes file, but I was wondering if it would be worth considering adding a priority (or similar name) to the route so that I can specify it being loaded last?
Maybe something like
Route::match(array('GET', 'POST'), '{slug}', function($slug)
{
// Handle the route
})->where('slug', '[\/_\-\_A-Za-z0-9]+')->priority('last');
Not sure if it helps, but you can try to use the
App::before(function(){ your package routes here });
or
App::after(function(){ your package routes here });
http://laravel.com/docs/lifecycle#application-events
Thanks, that is very helpful. I am able to use the App::before method and this works.
Might still be nice to have a priority on the route when creating them, but will see what others think.
App::before is a fine solution here.
Hi everyone, how can be done now with laravel 7/8? App::before told me method undefined...
Thank you very much