【问题标题】:Laravel - Route has a forward slashLaravel - 路线有一个正斜杠
【发布时间】:2019-04-30 07:06:11
【问题描述】:

这是我想在 Laravel 中访问文章的 URL。

http://mysite.test/art-entertainment-articles/poetry-articles/guide-praising-comments-1.html

现在 article_slug 是“/art-entertainment-articles/poetry-articles/guide-praise-cmets-1.html”。

我做了这样的路线。

Route::get('/{any:.*}', 'ArticlesController@article');

但它显示错误 404 未找到。现在我想通过匹配这样的蛞蝓来获取文章。

$article = Article::where('article_slug', '=', $article_slug)->first();

我应该在路线上写什么?它以斜线中断并计数不读取该方法。

【问题讨论】:

    标签: laravel


    【解决方案1】:

    像这样使用后备功能可能会更好

    Route::fallback(function () {
        //
    });
    

    这将捕获所有未在其上方定义的路由。然后你可以添加逻辑来点击你的控制器并从 url 中找出你需要的文章。

    【讨论】:

      猜你喜欢
      • 2020-11-13
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      相关资源
      最近更新 更多