Php 为具有多个参数的路由生成URL时,结果与预期不符

Php 为具有多个参数的路由生成URL时,结果与预期不符,php,laravel,routes,request,Php,Laravel,Routes,Request,当使用URL生成时,请求的结果在控制器中显示,反之亦然 我的路线: Route::get('district/{district}/municipal/{slug}', 'UIController@municipaldetail')->name('web-municipal_detail.show'); <a href="{{route('web-municipal_detail.show',['slug' => 1,'district'=>2] )}}" class=

当使用URL生成时,请求的结果在控制器中显示,反之亦然

我的路线:

Route::get('district/{district}/municipal/{slug}', 'UIController@municipaldetail')->name('web-municipal_detail.show');
<a href="{{route('web-municipal_detail.show',['slug' => 1,'district'=>2] )}}" class="btn btn-primary">++ More Details ++</a>
public function municipaldetail($slug, $district){
  dd($slug); // shows me the result of "2" and 
  dd($district); // shows me the result "1"
}
刀片:

Route::get('district/{district}/municipal/{slug}', 'UIController@municipaldetail')->name('web-municipal_detail.show');
<a href="{{route('web-municipal_detail.show',['slug' => 1,'district'=>2] )}}" class="btn btn-primary">++ More Details ++</a>
public function municipaldetail($slug, $district){
  dd($slug); // shows me the result of "2" and 
  dd($district); // shows me the result "1"
}
控制器

Route::get('district/{district}/municipal/{slug}', 'UIController@municipaldetail')->name('web-municipal_detail.show');
<a href="{{route('web-municipal_detail.show',['slug' => 1,'district'=>2] )}}" class="btn btn-primary">++ More Details ++</a>
public function municipaldetail($slug, $district){
  dd($slug); // shows me the result of "2" and 
  dd($district); // shows me the result "1"
}
但是当我颠倒请求的顺序时,它就可以正常工作了

public function municipaldetail($district,$slug ){
  dd($slug); // 1 
  dd($district); // 2
}

我不明白为什么会发生这种情况,请向我解释控制器是如何处理请求属性的,如果您需要进一步的详细信息,请务必告诉我,在这种情况下,路由参数将按顺序作为参数传递给您的方法

Route::get('test/{a}/{b}', function ($a, $b) {
    dd(compact('a', 'b'));
});
点击该路径:
yoursite.test/test/a/b

array:2 [▼
  "a" => "a"
  "b" => "b"
]
然后更改闭合参数的顺序:

Route::get('test/{a}/{b}', function ($b, $a) {
    dd(compact('a', 'b'));
});
然后再次点击路线:

array:2 [▼
  "a" => "b"
  "b" => "a"
]
它们的传递顺序与路由中定义的顺序相同