【问题标题】:laravel named route helper doesn't generate url with parametes.laravel 命名路由助手不会生成带参数的 url。
【发布时间】:2018-07-23 07:19:45
【问题描述】:

laravel 命名路由它生成我不想要的查询字符串。

来自文档:

LARAVEL 5.6

如果我在 LARAVEL 中访问命名路由会生成带有查询字符串的 URL 将参数传递给 route() 助手的第二个参数 不想要。我希望通过 URL 参数。

我的代码:

Route::get('/posts/count', 'PostController@index');

route(posts.index, [count => 3]) // /posts?3  
// i don't want this but i get it

route(posts.index, [count => 3]) // /posts/3  
// i want this but i don't get it

【问题讨论】:

  • 你能详细说明一下吗??
  • 您实际上需要有一个参数,需要在 URI 中替换任何其他内容作为查询参数添加
  • 你使用resource作为Route::resource(/posts', 'PostController');吗?
  • 你这里没有named route

标签: string laravel parameters named-routing


【解决方案1】:

您应该使用 {}

定义路由变量

喜欢这个

Route::get('/posts/{count}', 'PostController@index');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-10
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多