Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用户配置文件的Laravel路由?没有/用户_Php_Laravel - Fatal编程技术网

Php 用户配置文件的Laravel路由?没有/用户

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错误的情况下工作 我想尝试

在Laravel布线中:

我想让配置文件用户使用一个漂亮的URL:
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.php
Route::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']);