Php 用户配置文件的Laravel路由?没有/用户
在Laravel布线中: 我想让配置文件用户使用一个漂亮的URL:Php 用户配置文件的Laravel路由?没有/用户,php,laravel,Php,Laravel,在Laravel布线中: 我想让配置文件用户使用一个漂亮的URL:example.com/steve 实际上我有:example.com/user/steve 当我进行路由更新时,这会起作用: Route::get('{username}', ['as' => 'profile', 'uses' => 'ProfileController@show']); 但当我尝试进入其他路线(/guide)时: 此“折叠”与用户配置文件路由。我怎样才能使它在没有404错误的情况下工作 我想尝试
example.com/steve
实际上我有:example.com/user/steve
当我进行路由更新时,这会起作用:
Route::get('{username}', ['as' => 'profile', 'uses' => 'ProfileController@show']);
但当我尝试进入其他路线(/guide)时:
此“折叠”与用户配置文件路由。我怎样才能使它在没有404错误的情况下工作
我想尝试一种不同的方法,即“I方法”(将字母I放在所有URL之前:Route::get('I/guide'))
将路线分组并为其添加前缀您应该首先为指南创建路线
Route::get('guide', ['as' => 'guide', 'uses' => 'GuestController@showGuide']);
然后对用户
Route::get('{username}', ['as' => 'profile', 'uses' => 'ProfileController@show']);
在routes.php文件中,顺序确实很重要。如果{username}路由位于向导路由之上,则它将把向导视为{username},从而相应地重定向您,但您没有一个具有用户名向导的用户larvel从上到下匹配列出的路由。所以
\{username}
将匹配\{anyword}
解决这一问题的方法之一是
在your routes.phpRoute::get('guide',['as'=>'guide','uses'=>'GuestController@showGuide']);代码>应该放在第一位
让Route::get({username},['as'=>'profile','uses'=>'ProfileController@show']);代码>每隔一条路线放置一次
Route::get('guide', ['as' => 'guide', 'uses' => 'GuestController@showGuide']);
Route::get('{username}', ['as' => 'profile', 'uses' => 'ProfileController@show']);