【问题标题】:Laravel 5: return other route path by nameLaravel 5:按名称返回其他路由路径
【发布时间】:2017-08-08 08:44:17
【问题描述】:

我需要按名称返回其他路由路径(类似于/home/{page?}),我试过Route()

https://laravel.com/api/5.1/Illuminate/Contracts/Routing/UrlGenerator.html#method_route

Route('home');     //return http://localhost/home
Route('home',[1]);     //return http://localhost/home/1
Route('home',[1],false);     //return /home/1

但是我需要返回系统路径:/home/{page?},而home不是当前路由,

谢谢,

更新:

路线定义:

Route::GET('home/{page?}' ,array('uses'=>'News@home', 'as'=>'home'));

【问题讨论】:

  • 你能显示你的routes/web.php文件,你定义了这条路线吗?
  • @Jerodev 添加到问题
  • 其他路由部分是什么意思?你想得到的确切字符串是什么?
  • 我想得到这个home/{page?},这不是当前请求的路线
  • 请问您为什么想要这个?没有简单的方法可以做到这一点,您必须从应用程序路由器集合中获取它。

标签: php laravel laravel-5


【解决方案1】:

您可以使用route()函数中的关联数组按名称填写路由参数。

像这样:

$url = route('home', ['page' => 1]);

这样你就可以将参数按任意顺序放入数组中。

【讨论】:

    【解决方案2】:
    $urldata = route('home', ['page' => 1]);
    

    【讨论】:

      猜你喜欢
      • 2016-04-07
      • 2018-02-11
      • 1970-01-01
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多