Level 104
name is optional, so:
Route::get('/admin/category/{name?}', 'Admin\CategoryController@index')
->where('name','[index|list]');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, In laravel 5.5 I want to write 1 routes rule to make all next urls:
http://host.com/admin/category/list
http://host.com/admin/category/index
http://host.com/admin/category/
http://host.com/admin/category
to work for 1 control action.
I tried to write in routes :
Route::get('/admin/category/{name}', 'Admin\CategoryController@index')->where('name','[\/|index|list]+');
But only 2 first urls works ok, but the last 2 urls do not work. Which is the correct way ?
Thanks!
Write a specific route for edit, an place it before optional name route, so that if is matched first:
Route::get('/admin/category/edit','Admin\CategoryController@edit')
->where('name','[index|list]');
Route::get('/admin/category/{name?}', 'Admin\CategoryController@index')
->where('name','[index|list]');
Please or to participate in this conversation.