拥有下一条路线:
Route::get('/apartment/{apartment_name}', 'ApartmentController@getApartmentByName');
Route::get('/apartment/create', [
'uses' => 'ApartmentController@create',
'as' => 'apartment.create'
]);
Route::get('/apartment/edit', [
'uses' => 'ApartmentController@edit',
'as' => 'apartment.edit',
]);
我怎样才能在路线之间产生影响 myapp.com/apartment/create 和 myapp.com/apartment/beach-apartment
我想使用相同的URI前缀(apartment /)搜索公寓的名称,但是使用此代码我总是调用参数路径。
答案 0 :(得分:1)
这是因为无论是被调用,创建还是编辑,都在参数之一/apartment/{apartment_name}
内匹配,create
或edit
等于apartment_name
。
只需将参数1移动到该块中最下面的一行。
Route::get('/apartment/create', [
'uses' => 'ApartmentController@create',
'as' => 'apartment.create'
]);
Route::get('/apartment/edit', [
'uses' => 'ApartmentController@edit',
'as' => 'apartment.edit',
]);
Route::get('/apartment/{apartment_name}', 'ApartmentController@getApartmentByName');
使用此配置,如果/apartment/create
或/apartment/edit
未匹配,则它将匹配/apartment/{apartment_name}
。