php - 我怎样才能将一条捕获所有路线设置为 Laravel 中的最后一条路线

标签 php laravel-5.2 laravel-routing

我正在构建一个带有 SEO slug 的基本 CMS,所以我想在我的路线结束时捕获所有以获取 slug。所以在我的路线文件的末尾,我添加了:

Route::get('/{page?}', ['as' => 'Page', 'middleware' => 'web', 'uses' => 'PageController@index']);

效果很好,直到我添加了 Laravel File Manager ,它有自己的路线。这些路由添加在我的主路由文件中的所有路由之后。所以现在我的 catch all 收集了文件管理器的任何内容。

在运行 catch all 之前,如何加载所有其他路由,包括其他供应商文件夹中的路由?有没有一种方法可以声明路由不能匹配任何前缀为 laravel-filemanager 的路由?我无法在 Laravel 文档中或通过 Google 找到与此相关的任何内容。

这里要求的是我的应用提供商:

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    Illuminate\Bus\BusServiceProvider::class,
    Illuminate\Cache\CacheServiceProvider::class,
    Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
    Illuminate\Cookie\CookieServiceProvider::class,
    Illuminate\Database\DatabaseServiceProvider::class,
    Illuminate\Encryption\EncryptionServiceProvider::class,
    Illuminate\Filesystem\FilesystemServiceProvider::class,
    Illuminate\Foundation\Providers\FoundationServiceProvider::class,
    Illuminate\Hashing\HashServiceProvider::class,
    Illuminate\Mail\MailServiceProvider::class,
    Illuminate\Pagination\PaginationServiceProvider::class,
    Illuminate\Pipeline\PipelineServiceProvider::class,
    Illuminate\Queue\QueueServiceProvider::class,
    Illuminate\Redis\RedisServiceProvider::class,
    Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
    Illuminate\Session\SessionServiceProvider::class,
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,

    Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
    Caffeinated\Modules\ModulesServiceProvider::class,
    Intervention\Image\ImageServiceProvider::class,
    Spatie\Activitylog\ActivitylogServiceProvider::class,
    Spatie\Permission\PermissionServiceProvider::class,
    Unisharp\Ckeditor\ServiceProvider::class,
    Unisharp\Laravelfilemanager\LaravelFilemanagerServiceProvider::class,

],

最佳答案

只需尝试像这样在 app.php 中重新排序服务提供者:

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */

    Unisharp\Laravelfilemanager\LaravelFilemanagerServiceProvider::class,
    ... 
    App\Providers\RouteServiceProvider::class,
    ... 

],

无论如何,如果不是特殊情况,我总是在列表末尾写RouteServiceProvider

关于php - 我怎样才能将一条捕获所有路线设置为 Laravel 中的最后一条路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38304843/

相关文章:

javascript - 如何将多个电子邮件 ID 添加到文本字段(如 Facebook 隐私设置)并将电子邮件 ID 列表转换为逗号分隔列表?

php - 扩展 Laravel 5.2 SessionGuard

laravel - RequestGuard::attempt 不存在

php - Laravel Route 资源 MethodNotAllowedHttpException on destroy 方法

javascript - 处理嵌套文件包含在 php 中并将值返回给 javascript 函数

php - 从文件夹加载所有 .php 文件

php - 使用多个 Laravel 5 项目跨子域共享身份验证 session

laravel - 仅删除单个方法的 csrf token - Laravel

php - Laravel PUT 路由结果为 404

php - 将按钮添加到 HTML 表中的行,并带有指向 URL 的链接,该 URL 包含该行中另一列的数据