如何在同一位置传递不同的动态参数以访问Laravel中的不同视图页面

问题描述 投票:1回答:1

这些是我面临问题的路线

获取特定城市注册地点列表的途径

Ex: http://localhost:8000/London

Route::group(['namespace' => 'Page'], function() {
    Route::group(['prefix' => '{city}', 'where'  => ['city' => '[\w\d]+']], function() {
        Route::get('/', 'CityPageController@showCityPage')->name('cityPage');
    });
});

获取特定用户个人资料及其评论,照片等详细信息的途径

Ex: http://localhost:8000/Johnhttp://localhost:8000/John/reviewshttp://localhost:8000/John/photos

Route::group(['namespace' => 'User'], function() {
    Route::group(['middleware' => 'verified'], function() {
        Route::group(['prefix' => '{username}', 'where'  => ['username' => '[\w\d]+']], function() {
            Route::get('/', 'ProfileController@showProfilePage')->name('profilePage');
            Route::get('/reviews', 'ReviewController@showReviewPage')->name('reviewPage');
            Route::get('/photos', 'ImageController@showPhotoPage')->name('photoPage');
        });
    });
});

问题是这两个路由都无法同时工作。

居于另一方之上的路径优先于另一条路径。

如何解决路由问题。

laravel routing laravel-routing laravel-route
1个回答
1
投票

从Laravels的角度来看,两个URL相同:

{property}/具有不同属性名称cityusername不会有所区别,因为laravel无法理解伦敦是一个城市,并且说Prateek是用户名。

我建议的更好的方法是在前缀EX之前添加型号名称的标识符。 Route::group(['prefix' => 'users/{username}' ...代替您在城市路线之前的进场和城市。

看看这个:https://laravel.com/docs/6.x/controllers#resource-controllers

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.