【问题标题】:Laravel route starting with a specific string以特定字符串开头的 Laravel 路由
【发布时间】:2015-09-22 08:09:09
【问题描述】:

我需要创建一个包含一些固定和动态部分的路线。基本上我需要灵活处理 url 的第二段。如果 url 以 'products/test....' 开头,则路由必须转到 PageController,所有其他以 'products/....' 开头的路由都必须转到 ProductController。

// Something like this:
Route::any('products/".starts_with($slug, 'test'), [
    'uses' => 'PageController@show'
])->where('slug', '(.*)?');

Route::get('products/{slug}', [
    'uses' => 'ProductController@show'
]);

这在 Laravel 5 中可行吗?

【问题讨论】:

  • 那么这条路线有什么问题?
  • 'starts_with($slug, 'test')' 部分。不工作,以我试图实现的目标为例。
  • 你能在这里展示你试图实现的示例网址吗?
  • 你可以试试Route::any('products/test/{slug}', ["usage"=>"PageController@show"])

标签: php routes laravel-5


【解决方案1】:

在 Laravel 5 中,我们使用中间件作为路由的助手。 默认安装中有一些示例,您可以根据自己的代码进行调整。这是解决此问题的最佳方法。

【讨论】:

  • 好的,我会深入研究的。
猜你喜欢
  • 2017-08-08
  • 1970-01-01
  • 2017-09-20
  • 1970-01-01
  • 2020-05-11
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多