1

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?

2
  • Have you tried passing an array through? instead of comma separated params Commented Jan 18, 2019 at 17:20
  • I haven't, I've only done it this way but I have the $id variable separate from the $form array with the grouping element, so I didn't know if I could send them both taht way Commented Jan 18, 2019 at 17:22

2 Answers 2

3

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']) }}
Sign up to request clarification or add additional context in comments.

1 Comment

@Whisou138 Glad it helps :)
2

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

1 Comment

$grouping should be $form['grouping'] !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.