简体   繁体   中英

Pass multiple arguments to route/controller in laravel

I'm trying to pass two variables/arguments from my view through a link

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

and call the route

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

And call this function with those two arguments

public function testing($id,$grouping){

}

It doesn't seem to be working though. Is my error in my route or my link call?

If you want to have parameters to be passed into controller's method, you need to define route parameters like this

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

then you can have it in controller method:

public function testing($id, $grouping)

To generate route for above definition, the second parameter is the array of params to pass. So it will become

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

To pass parameters in a route use an array with the paramter names as keys:

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

Laravel Doc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM