【问题标题】:Laravel Route Can Not Find By Route NameLaravel Route Can Not Find By Route Name
【发布时间】:2022-12-01 15:09:38
【问题描述】:

This is My Route

Route::namespace("Core\Controller\Site")
        ->prefix("/")
        ->name("site.")
        ->group(function () {
 Route::get("{slug}", "NewsController@index")->name("news.index");
            Route::get("show/{slug}", "NewsController@show")->name("news.show");
            Route::get("{slug}", "ArticleController@index")->name("article.index");
            Route::get("show/{slug}", "ArticleController@show")->name("article.show");
            Route::get("{slug}", "VideoController@index")->name("video.index");       
});

This is My a href which is I used This Route

<a href="{{ route('site.news.show', $item->slug) }}"></a>

It gives Such Kind Of Error

Route [site.news.show] not defined.

【问题讨论】:

    标签: laravel routes


    【解决方案1】:

    You are using the same route paths (show/{slug} and {slug}) with the same methods for different route names. I think they override each other. Try to use different route paths.

    【讨论】:

    • nice catch ;) ;)
    【解决方案2】:

    change the name of the route and it will work.

    show_news and show_article

    Route::namespace("CoreControllerSite")
            ->prefix("/")
            ->name("site.")
            ->group(function () {
     Route::get("{slug}", "NewsController@index")->name("news.index");
                Route::get("show_news/{slug}", "NewsController@show")->name("news.show");
                Route::get("{slug}", "ArticleController@index")->name("article.index");
                Route::get("show_article/{slug}", "ArticleController@show")->name("article.show");
                Route::get("{slug}", "VideoController@index")->name("video.index");       
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-30
      • 2018-12-27
      • 1970-01-01
      • 2014-06-23
      • 2020-04-12
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多