i have 2 routes, one for the admin and other posts, but they are conflicting, since in the Posts routes i could have another slug that is the category.
Example:
Route::get('{category?}/{slug}',
[\App\Http\Controllers\Site\PostController::class, 'show']);
Route::prefix('admin')->group(function () {
Route::get('/login', 'App\Http\Controllers\Auth\LoginController@showLoginForm')->name('login');...
How can i resolve it without adding other prefix to the Post or Admin? I see in the docs that i can use regular expressions but there isnt a ways of for example ignoring the "admin" word or something
My Answer:
> One way to resolve this conflict is to define the admin route before the posts route. This way, when a request is made to the admin route, it will be matched first and the posts route will not be triggered.
php
Route::prefix('admin')->group(function () {
// Define admin routes here
});
Route::get('{category?}/{slug}', [\App\Http\Controllers\Site\PostController::class, 'show']);
This way, requests to the admin route will be handled separately from requests to the posts route, avoiding conflicts between the two.
Rate this post
3 of 5 based on 5030 votesComments