簡體   English   中英

將多個參數傳遞給laravel中的route / controller

[英]Pass multiple arguments to route/controller in laravel

我正在嘗試通過鏈接從視圖傳遞兩個變量/參數

<a href="{{ route('shop.order.test', $id,$form['grouping']) }}"

並呼叫路線

Route::get('ordering/test', 'Shop\OrderingController@testing')
  ->name('shop.order.test'); 

並使用這兩個參數調用此函數

public function testing($id,$grouping){

}

它似乎沒有用。 我的路線或鏈接通話有誤嗎?

如果要將參數傳遞到控制器的方法中,則需要像這樣定義路由參數

Route::get('ordering/test/{id}/{grouping}', 'Shop\OrderingController@testing');

然后可以在控制器方法中使用它:

public function testing($id, $grouping)

為了生成上述定義的路由,第二個參數是要傳遞的參數數組。 所以它將成為

{{ route('shop.order.test', ['id' => $id, 'grouping' => $form['grouping']) }}

要在路由中傳遞參數,請使用參數名稱作為鍵的數組:

{{ route('shop.order.test', ['id' => $id, 'grouping' => $form['grouping']]) }}

Laravel Doc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM