Reputation: 7138
I try to get my route without any additional parameter in url and i'm getting Sorry, the page you are looking for could not be found.
error.
If I use url like: domain/category/lenovo
where lenovo is my slug it's working. But if I try to get my url like: domain/lenovo
I'm gettin error above.
here is my codes:
route
Route::get('/{categoryslug}', 'frontend\FrontendController@totalcategoriessubs')->name('catwithsubs')->where('categoryslug', '[\w\d\-\_]+');
function
public function totalcategoriessubs($categoryslug) {
$categories = Category::where('slug','=',$categoryslug)->with('subcategories')->paginate(12);
return view('front.categoriessubs', compact('categories'));
}
it also brakes my other urls such as domain/admin/dashboard
etc.
any idea?
Upvotes: 0
Views: 424
Reputation: 14271
It seems that is caused by the order of your routes.
Your actual problem is that when you hit a fixed endpoint, for example /dashboard
this will be handled by Route::get('/{categoryslug}', ...)
before the correct endpoint (Route::get('dashboard', ...)
). So, as your system notices that there is no category with that slug (dashboard
) it throws the error.
Try change the order of your routes, like this:
Route::get('/category/{categorySlug}', 'CategoryController@index');
Route::get('/dashboard', 'DashboardController@home');
// and so on..
Route::get('/{categoryslug}', 'frontend\FrontendController@totalcategoriessubs')
->name('catwithsubs')->where('categoryslug', '[\w\d\-\_]+');
Always put the routes that have fixed parts (.../category/...
)of the route before the ones that have dynamic elements (.../{categoryslug}/
).
Upvotes: 2