Laravel 5.5路线订单不起作用

Laravel 5.5路线订单不起作用,laravel,routing,Laravel,Routing,我有以下路线: Route::group(['middleware' => ['ForLoggedIn']], function() { //article actions Route::get ('blog/gallery', 'ContentController@showGallery'); Route::get ('blog/import', 'ContentController@importArticles'); Route::get ('blog

我有以下路线:

Route::group(['middleware' => ['ForLoggedIn']], function()
{

    //article actions
    Route::get ('blog/gallery', 'ContentController@showGallery');
    Route::get ('blog/import', 'ContentController@importArticles');
    Route::get ('blog/{article}/edit', 'ContentController@editArticle');
    Route::get ('blog/all', 'ContentController@allArticlesList');
    Route::get ('blog/add', 'ContentController@addArticle');
});

Route::get ('blog/{article}', 'ContentController@blogArticle');
路线应该考虑次序正确吗?奇怪的事情发生了。”blog/all和blog/gallery最后一个ContentController@blogArticle. 然而,“blog/add”效果很好

这怎么可能?我尝试了所有我找到的缓存清除。你知道哪里不对吗?谢谢你的提示

编辑
当我评论最后一条路线时,一切正常。

我认为您需要遵循laravel资源路线

如果您在一个控制器中工作,则需要在路线中遵循此顺序

索引、创建、存储、显示、编辑、更新、销毁

声明于

试着把这条路

Route::get ('blog/add', 'ContentController@addArticle');
以前

Route::get ('blog/{article}/edit', 'ContentController@editArticle');

一般来说,laravel会找到自上而下的路线匹配

因此,请尝试以下路线:

Route::group(['middleware' => ['ForLoggedIn']], function()
{
    //article actions
    Route::get ('blog/gallery', 'ContentController@showGallery');
    Route::get ('blog/import', 'ContentController@importArticles');
    Route::get ('blog/all', 'ContentController@allArticlesList');
    Route::get ('blog/add', 'ContentController@addArt`enter code here`icle');
    Route::get ('blog/{article}/edit', 'ContentController@editArticle');
});
Route::get ('blog/{article}', 'ContentController@blogArticle');

TL;DR:我不知道这是否真的回答了这个问题,但我正要发布我自己的问题答案,这时我遇到了一个类似的问题,并在GitHub上发布到laravel/framework项目。查看
$route:list--sort
,查看按考虑顺序排列的实际路线列表

// Handle the public
Route::resource('your-resource', YourResourceController::class, [
        'only' => [
            'index',
            'show'
        ]
    ])
    ->middleware(['web']);

// Put everything else behind a wall
Route::resource('your-resource, YourResourceController::class, [
        'except' => [
            'index',
            'show'
        ]
    ])
    ->middleware(['web', 'auth']);
Create(/Create)以show(/{your resource})结束<代码>路线:列表显示以下内容

your-resource
your-resource
your-resource/create
your-resource/{your-resource}
从而隐藏了“缺陷”,即解释顺序实际上是:

your-resource
your-resource
your-resource/{your-resource}
your-resource/create
由于线路区段的顺序。切换它们可以解决问题:

// Put everything else behind a wall
Route::resource('your-resource, YourResourceController::class, [
        'except' => [
            'index',
            'show'
        ]
    ])
    ->middleware(['web', 'auth']);

// Handle the public
Route::resource('your-resource', YourResourceController::class, [
        'only' => [
            'index',
            'show'
        ]
    ])
    ->middleware(['web']);

如果你输入php artisan route:list,结果会怎样?我会得到一个路由列表。命令是正确的。通过更改路线的顺序,我可以使其中一条路线正常工作。我不知道为什么会发生这样的事,我帮不上忙。我尝试了所有的顺序组合,但我最多可以得到2条路线。用一些组合,什么都不起作用。嗨,乔希,“除了”解决了问题。路由:列表中的顺序正确。改变路线的顺序没有任何帮助。它可能会变得更糟,但不会更好:)谢谢!