【问题标题】:how to call different controller's method with the same route in Laravel如何在 Laravel 中使用相同的路由调用不同的控制器方法
【发布时间】:2018-09-10 01:50:46
【问题描述】:

假设我在category(电脑配件)下有一些services(例如:鼠标、键盘、显示器)。对于category,路由是http://url.com/category。现在我想要services 的路由将是http://url.com/category/services/{{service-name (ex:mouse/keyboard)}}

也称为路由的两个不同函数。为路由http://url.com/category 调用category() 函数,为路由http://url.com/category/services/{{service-name (ex:mouse/keyboard)}} 调用services() 函数

这怎么可能?

【问题讨论】:

    标签: laravel laravel-5.3 laravel-routing


    【解决方案1】:

    更改顺序。先处理路由http://url.com/category/services/{{service-name}},再处理http://url.com/category。 routes/web.php 是先到先得。所以正确设置顺序。

    或将http://url.com/category 更改为更规范的http://url.com/categories

    【讨论】:

      猜你喜欢
      • 2016-03-03
      • 1970-01-01
      • 2021-11-05
      • 2021-05-26
      • 2018-04-25
      • 2013-09-24
      • 2016-03-29
      • 2017-04-05
      • 2016-10-03
      相关资源
      最近更新 更多