We have 3 types of urls:
- Countries like: /germany-travel or /united-kingdom-travel
- Cities like: /berlin or /los-angeles
- Artikles like: /my-great-article or /my-other-great-article
To separete these 3 types of urls, I need a working routing in laravel, based on slugs on my 3 database models Country, City and Article.
// Country
Route::get('{country}-travel', function(\App\Models\Country $country){
return view('country.show', ["object" => $country]);
});
// City
Route::get('{city}', function(\App\Models\City $city){
return view('city.show', ["object" => $city]);
})->where("city", "[a-z-]+");
// Articles
Route::get('{article?}', function(\App\Models\Article $article){
return view('article.show', ["object" => $article]);
}))->where('article', '.*');
This only works for countries and cities, since '/my-great-article' is also treated as city (and because of this, I get an 404 not found, since there is no city with "my-great-article" slug. Any ideas?