6

Main App Routes:

Route::get('/login', [
    'as' => 'user.login', 
    'uses' => 'LoginController@login'
];
Route::get('/logout', [
    'as' => 'user.logout', 
    'uses' => 'LoginController@logout'
];
Route::get('/admin', [
    'as' => 'admin.index', 
    'uses' => 'AdminController@index'
];

I have a package (vendor) (example : metrakit/mypackage) with a routes.php file. In this file I have a route :

Route::get('/{slug}', [
    'as' => 'item.show', 
    'uses' => 'ItemController@show'
]; 

This route overload all my main routes ! My routes like "/login", "/logout", "/bob", ... are all redirected to my controller ItemController.

I don't want to have a route like

Route::get('/item/{slug}', array('as' => 'item.show', 'uses' => 'ItemController@show'); 

I thinks, I have to do a route pattern like this :

Route::pattern('slug', '^((?!(login|logout|admin)).)*$'); 

But it looks a bit dirty and it's not dynamic.

So Im searching about a better solution.

Ajay Kumar Ganesh
  • 1,838
  • 2
  • 25
  • 33
Metra
  • 393
  • 5
  • 20
  • The issue is the order in which routes are loaded. You're probably using the loading of your custom routes in the package `boot()` method. This loads your package routes prior to your regular routes. Placing a catchall route at the top will do what you're seeing right now. I guess your best option would be to not autoload the routes from your package within the boot method, but manually loading them in the before filter (after your regular routes are loaded). – Robert May 13 '15 at 09:16

2 Answers2

0

It might be as simple as loading your vendor's service provider late in your app.php file. Routes are processed in the sequence they are registered.

Anthony
  • 5,275
  • 11
  • 50
  • 86
0

Looks like you did the right way. A problem that might happen is when adding a new route in your route.php file, you'd have to add in your route pattern as well. However, it could be solved by creating a global variable for setting it only once.

henriale
  • 1,012
  • 9
  • 21