How not to overload the main routes with packet routes?

The main application 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 (provider) (example: metrakit / mypackage) with a route.php file. In this file, I have a route:

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

This route overloads all my main routes! My routes, such as "/ login", "/ logout", "/ bob", ..., are redirected to my ItemController.

I do not want to have a route like

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

I think I need to make a route pattern as follows:

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

But he looks a little dirty and not dynamic.

So, I was looking for the best solution.

+6
source share
2 answers

Looks like you made the right path. The problem that may arise is adding a new route to the route.php file, you also need to add the route to your template. However, it could be solved by creating a global variable to set it only once.

0
source

It can be as simple as loading a vendor vendor vendor at the end of your app.php file. Routes are processed in the order in which they are registered.

0
source

Source: https://habr.com/ru/post/986710/


All Articles