Laravel 5-如何在GET路由中传递多个参数?

时间:2018-10-12 10:04:24

标签: php laravel-5

任何人都可以帮助我在GET方法中传递多个参数,我有以下代码-

在刀片中-

 @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

在途中-

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

但是它抛出错误-

  

缺少[Route:frontend.model] [URI:所需的参数:   型号/品牌/ {品牌} /年份/ {年份} / niceName / {niceName} / {类型?}]

2 个答案:

答案 0 :(得分:2)

要在路由中传递参数,请使用参数名称作为键的数组:

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

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

答案 1 :(得分:0)

在Laravel 5.2中,使用以下示例:

在view.blade.php

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

在route.php中

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

在控制器方法中,将参数作为函数参数传递,如下所示:

 public function searchUsers($id, $name)
    {
      // your code here that use the parameters
    }