在 Laravel 路由中:
我想让个人资料用户的 URL 变得更好:example.com/steve
实际上我有:example.com/user/steve
当我进行路由更新时,这有效:
Route::get('{username}', ['as' => 'profile', 'uses' => 'ProfileController@show']);
但是当我尝试进入另一条路线(/guide)时:
Route::get('guide', ['as' => 'guide', 'uses' => 'GuestController@showGuide']);
此“崩溃”与用户配置文件路线。我怎样才能使其正常工作而不会出现 404 错误?
我想尝试使用另一种方法“i 方法”(将字母 i 放在所有 URL 之前:Route::get('i/guide'))
最佳答案
Laravel 从上到下匹配列出的路线。所以\{username}
将匹配\{anyword}
解决此问题的方法之一是;
在你的routes.php Route::get('guide', ['as' => 'guide', 'uses' => 'GuestController@showGuide']);
应该是第一位的。
让Route::get('{username}', ['as' => 'profile', 'uses' => 'ProfileController@show']);
放置在所有其他路线之后
关于php - Laravel 的用户配置文件路线?无/用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30148242/