Answer the question
In order to leave comments, you need to log in
How to specify city in url?
There are multiple urls
Route::get('part/{slug}', [App\Http\Controllers\PartsController::class, 'part'])->name('part');
Route::get('parts', [App\Http\Controllers\PartsController::class, 'parts'])->name('parts');
Route::get('spare-cars/{marka?}/{model?}/{slug?}', [App\Http\Controllers\CarController::class, 'spareCars'])->name('spare.cars');
Answer the question
In order to leave comments, you need to log in
They suggested a solution to the problem on stackoverflow
We add all routes to the group and do processing if we entered without a city, I don’t know how correct this solution is, but at the moment this solution works
Route::prefix('{city?}')->group(function() {
Route::get('part/{slug}', [App\Http\Controllers\PartsController::class, 'part'])->name('part');
Route::get('parts', [App\Http\Controllers\PartsController::class, 'parts'])->name('parts');
Route::get('spare-cars/{marka?}/{model?}/{slug?}', [App\Http\Controllers\CarController::class, 'spareCars'])->name('spare.cars');
Route::get('/', [App\Http\Controllers\PartsController::class, 'checkUrl'])->name('checkUrl');
});
public function checkUrl($slug) {
if($slug == 'parts') {
return redirect('moskva/parts');
} else if($slug == 'part') {
return redirect('moskva/part');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question