0

Is possible have two variables and same start of URL?
I mean 'turnaje/{tournament}' and 'turnaje/{region}'.

Route::get('/turnaje', [TournamentController::class, 'index']);
Route::get('/turnaje/pridat', [TournamentController::class, 'create'])
    ->middleware('auth');
Route::get('/turnaj/{tournament}', [TournamentController::class, 'show']);
Route::get('/turnaje/{region}', [TournamentController::class, 'show_region']);

Route::resource('turnaje', TournamentController::class)
    ->parameters(['tournaments' => 'tournaments:slug'])
    ->except(['index', 'show', 'choose', 'create'])
    ->middleware('auth');
Syscall
  • 19,327
  • 10
  • 37
  • 52
Tom_hutka
  • 15
  • 4
  • 2
    No, you can't have the same pattern for two routes. How would the router know which of the two to choose? – El_Vanja Jan 30 '21 at 19:06

2 Answers2

1

No it's not possible because after Laravel is confused, doesnt know what do zou want.

1

This is possible by two ways

If param can be resolved by https://laravel.com/docs/8.x/routing#parameters-regular-expression-constraints (one has numerical id, second has slug, etc.)

Or create shared controller thats resolve by required param

  • find in regions
  • if not found, find in tournaments
  • cannot use implicit binding, must use string

But I recommend splitting it exactly by route /{region}/turnaje

Daniel Šádek
  • 662
  • 5
  • 10