Reputation: 282825
I want to create 3 different routes like this:
Route::get('schedule',['as'=>'schedule.view','uses'=>'ScheduleController@view']);
Route::get('schedule/{year}-{month}',['as'=>'schedule.view','uses'=>'ScheduleController@view'])
->where('year','\d{4}')
->where('month','0[1-9]|1[0-2]');
Route::get('schedule/{year}-{month}-{day}',['as'=>'schedule.view','uses'=>'ScheduleController@view'])
->where('year','\d{4}')
->where('month','0[1-9]|1[0-2]')
->where('day','0[1-9]|[12][0-9]|3[01]');
i.e., you can provide one of:
The routes work as-is when I link to them with route('schedule.view', ['2015','01','01])
but if I omit the parameters it tries linking to /schedule/{year}-{month}-{day}
(with the braces actually in there!).
Is there a way to get laravel to behave smarter or do I have to give each my routes a different name?
Upvotes: 0
Views: 215
Reputation: 8520
It's definitely not possible that way because route()
reads them out of an array indexed by name.
One route per name. So it looks like only the last route will be in that array and the others get overriden.
The function that returns the route does nothing else than:
return isset($this->nameList[$name]) ? $this->nameList[$name] : null;
So a different name seems to be the way to go.
Upvotes: 2