Reputation: 3068
I am going to make own CMS based on laravel nova. Now I'm making a 'Pages' functional. I will put my pages as rows of the table pages
that will contains the url
column. In the end of my routes/web.php
file, I have the route that matches with any route:
Route::get( .... );
Route::post( .... );
Route::get('/{page}', 'PageController@myRouter')->where('page', '[A-Za-z0-9_\-\/]+');
In the myRoute
method I will catch an url and try to find the page with this url in the database; All works fine, but when I type <domain_of_my_site>/nova
to getting admin panel, I have 404. Because of, nova's routes are included later than my route-for-any-request. So, how to fix it? How I can put this
Route::get('/{page}', 'PageController@myRouter')->where('page', '[A-Za-z0-9_\-\/]+');
really in the end?
Upvotes: 2
Views: 782
Reputation: 1540
I had a similar issue with generic slugs in my routes file. I managed to limit the pattern for the slugs to alpha-numeric characters (including dashes, hyphens and slashes*) but exclude the Nova routes (nova-api
and nova-vendor
) as well as the Nova path to the admin panel (nova
).
This is how the routes/web.php
file looks like:
Route::get('/{page}', 'PageController@myRouter');
And the pattern for {page}
in the RouteServiceProvider
in the app/Providers/RouteServiceProvider.php
file:
public function boot()
{
Route::pattern('page', '^(?!nova|nova-api|nova-vendor).[a-zA-Z0-9-_\/]+$');
parent::boot();
}
*) Please note that this pattern also allows slugs like /page/one/two
.
Upvotes: 1