1

Can anyone please help me to pass multiple parameters in GET method, I have following codes -

in blade -

 @if(!isset($model->id_car_type))
     <a class="btn btn-search-red" href="{{ route('frontend.model', [Request::segment(2),$model->year,$model->niceName]) }}">Select</a>
 @else
     <a class="btn btn-search-red" href="{{ route('frontend.model', array(Request::segment(2),$model->year,$model->niceName, $model->id_car_type)) }}">Select</a>
 @endif

In route -

Route::get('/model/{make}/{year}/{niceName}/{type?}', 'GeneralController@trimShowByNiceName')->name('frontend.model');

But it is throwing error -

Missing required parameters for [Route: frontend.model] [URI: model/make/{make}/year/{year}/niceName/{niceName}/{type?}]

Sachin Vairagi
  • 4,894
  • 4
  • 35
  • 61
  • 2
    Maybe this will help you. [Link here](https://stackoverflow.com/questions/31681715/passing-multiple-parameters-to-controller-in-laravel-5) – MONSTEEEER Oct 12 '18 at 10:15
  • I have tried but couldn't success – Sachin Vairagi Oct 12 '18 at 10:18
  • Debugging is the best way to find solution and trust me it works 90% of the times. Let me guide you to the right path, in route (backend) there are certain parameters which are set as required. Log request body of the route and check which one of the required parameters are not being received. – Nishant Ghodke Oct 12 '18 at 10:53

2 Answers2

4

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

{{ route('frontend.model', ['make' => 'Ford', 'year' => 1988, 'niceName' => 'Ford Escort']) }}

https://laravel.com/docs/5.7/routing#named-routes

brombeer
  • 8,716
  • 5
  • 21
  • 27
0

In Laravel 5.2 use the following example:

In the view.blade.php

<a href="{{ route('users', [$users->id, $users->name]) }}">Page</a>

In the route.php

`Route::get('users/{id}{name}', 'UsersController@searchUsers'); // this gets the id, name` from the view url.

In the controller method, pass the parameters as function parameters as follows:

 public function searchUsers($id, $name)
    {
      // your code here that use the parameters
    }
Jose Mhlanga
  • 805
  • 12
  • 14