首页 > 解决方案 > 在 laravel 中找不到资源的奇怪问题

问题描述

我在一个博客网站工作。我有以下路线

/categories              App\Http\Controllers\Frontend\Blog\CategoryController@index  
/category/{slug}         App\Http\Controllers\Frontend\Blog\CategoryController@show    
/tags                    App\Http\Controllers\Frontend\Blog\TagController@index
/tag/{slug}              App\Http\Controllers\Frontend\Blog\TagController@show

除 /tags 外,所有路线都运行良好

它显示以下屏幕。

在此处输入图像描述

当我将此路线更改为其他路线时,它可以完美运行,\tags\tag-listing可能会错过什么问题?如果需要,我可以添加更多详细信息。

更新

RouteServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        $this->mapBackendRoutes();

        $this->mapFrontendRoutes();
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }

    /**
     * Define the "backend" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapBackendRoutes()
    {
        Route::prefix('backend')
            ->middleware('web','auth')
            ->namespace($this->namespace)
            ->group(base_path('routes/backend.php'));
    }

    /**
     * Define the "backend" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapFrontendRoutes()
    {
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/frontend.php'));
    }
}

路线/前端.php

<?php
$router->group(['namespace' => 'Frontend'], function ($router){
    require app_path('Http/Routes/Frontend/home.php');
});

$router->group(['namespace' => 'Frontend\Blog'], function ($router){
    require app_path('Http/Routes/Frontend/category.php');
    require app_path('Http/Routes/Frontend/tag.php');
    require app_path('Http/Routes/Frontend/post.php');
    require app_path('Http/Routes/Frontend/page.php');
});

应用程序/Http/Routes/tag.php

<?php

$router->get('/tags', 'TagController@index')->name('frontend.tags');
$router->get('/tag/{slug}', 'TagController@show')->name('frontend.tags.show');
$router->get('/tag/{slug}/load-more-posts', 'TagController@loadMorePosts')->name('frontend.tags.load-more-posts');

$router->get('/load-more-tags', 'TagController@loadMoreTags')->name('frontend.tags.load-more');

应用程序/Http/Routes/category.php

<?php

$router->get('/categories', 'CategoryController@index')->name('frontend.categories');
$router->get('/category/{slug}', 'CategoryController@show')->name('frontend.categories.show');
$router->get('/category/{slug}/load-more-posts', 'CategoryController@loadMorePosts')->name('frontend.categories.load-more-posts');

$router->get('/load-more-categories', 'CategoryController@loadMoreCategories')->name('frontend.categories.load-more');

我不知道这里有什么问题。

标签: phplaravelroutes

解决方案


推荐阅读