Laravel如何创建查询字符串但不像url路径?

时间:2017-04-10 19:23:13

标签: laravel url

我试图用laravel创建一个url查询字符串但是这个方法:

url()->to('categories', ['id' => 1, 'name' => 'cars']);

返回我:

http://localhost/categories/1/cars

但我需要这个:

http://localhost/categories?id=1&name=cars

2 个答案:

答案 0 :(得分:2)

首先,您需要创建一个没有参数的命名路由:

Route::get('categories', ['as' => 'categories', 'uses' => 'SomeController@showCategories']);

然后使用route()助手:

route('categories', ['id' => 1, 'name' => 'cars']);

这将产生:

'/categories?id=1&name=cars'

答案 1 :(得分:0)

答案是:

public ListBoxModel doFillAuthTokenCredentialIdItems(){
  Jenkins jenkins = Jenkins.getInstance();

  if (jenkins == null) {
    return new ListBoxModel();
  }

  if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
    return new ListBoxModel();
  }
  AbstractIdCredentialsListBoxModel model = new StandardListBoxModel().includeEmptyValue().includeAs(ACL.SYSTEM, jenkins, VaultTokenCredential.class);
  return model;
}