如何在根URL中使用slug

时间:2015-08-19 20:46:16

标签: php routes laravel-5.1

我正在研究自己的CMS,但是我遇到了一些slug的困难,所以,这是我的问题:

我正试图在我的网址根目录上使用slug:

click then go to line

此时我的app / routes.php

中有以下条目
Route::get('/', 'ArticleController@index');
Route::get('/{slug?}', 'ArticleController@show');

当我尝试进入网站的“登录”区域时会出现问题,默认位于/ home(我在Laravel 5.1中使用脚手架进行用户身份验证)

当我输入domain.com/home的URL时,它仍然将其称为slug。

这是我的路线:列表

+--------+--------------------------------+-------------------------------------------------------+----------------------+------------------------------------------------------------+------------+
| Domain | Method                         | URI                                                   | Name                 | Action                                                     | Middleware |
+--------+--------------------------------+-------------------------------------------------------+----------------------+------------------------------------------------------------+------------+
|        | GET|HEAD                       | /                                                     |                      | App\Http\Controllers\ArticleController@index               |            |
|        | POST                           | auth/login                                            |                      | App\Http\Controllers\Auth\AuthController@postLogin         | guest      |
|        | GET|HEAD                       | auth/login                                            |                      | App\Http\Controllers\Auth\AuthController@getLogin          | guest      |
|        | POST                           | auth/login/{one?}/{two?}/{three?}/{four?}/{five?}     |                      | App\Http\Controllers\Auth\AuthController@postLogin         | guest      |
|        | GET|HEAD                       | auth/login/{one?}/{two?}/{three?}/{four?}/{five?}     |                      | App\Http\Controllers\Auth\AuthController@getLogin          | guest      |
|        | GET|HEAD                       | auth/logout                                           |                      | App\Http\Controllers\Auth\AuthController@getLogout         |            |
|        | GET|HEAD                       | auth/logout/{one?}/{two?}/{three?}/{four?}/{five?}    |                      | App\Http\Controllers\Auth\AuthController@getLogout         |            |
|        | POST                           | auth/register                                         |                      | App\Http\Controllers\Auth\AuthController@postRegister      | guest      |
|        | GET|HEAD                       | auth/register                                         |                      | App\Http\Controllers\Auth\AuthController@getRegister       | guest      |
|        | GET|HEAD                       | auth/register/{one?}/{two?}/{three?}/{four?}/{five?}  |                      | App\Http\Controllers\Auth\AuthController@getRegister       | guest      |
|        | POST                           | auth/register/{one?}/{two?}/{three?}/{four?}/{five?}  |                      | App\Http\Controllers\Auth\AuthController@postRegister      | guest      |
|        | GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing}                                       |                      | App\Http\Controllers\Auth\AuthController@missingMethod     | guest      |
|        | GET|HEAD                       | home                                                  |                      | \Bestmomo\Scafold\Http\Controllers\HomeController@index    | auth       |
|        | POST                           | home/article                                          | home.article.store   | App\Http\Controllers\ArticleController@store               | auth       |
|        | GET|HEAD                       | home/article                                          | home.article.index   | App\Http\Controllers\ArticleController@index               | auth       |
|        | GET|HEAD                       | home/article/create                                   | home.article.create  | App\Http\Controllers\ArticleController@create              | auth       |
|        | GET|HEAD                       | home/article/{article}                                | home.article.show    | App\Http\Controllers\ArticleController@show                | auth       |
|        | PUT                            | home/article/{article}                                | home.article.update  | App\Http\Controllers\ArticleController@update              | auth       |
|        | DELETE                         | home/article/{article}                                | home.article.destroy | App\Http\Controllers\ArticleController@destroy             | auth       |
|        | PATCH                          | home/article/{article}                                |                      | App\Http\Controllers\ArticleController@update              | auth       |
|        | GET|HEAD                       | home/article/{article}/edit                           | home.article.edit    | App\Http\Controllers\ArticleController@edit                | auth       |
|        | GET|HEAD                       | password/email/{one?}/{two?}/{three?}/{four?}/{five?} |                      | App\Http\Controllers\Auth\PasswordController@getEmail      | guest      |
|        | POST                           | password/email/{one?}/{two?}/{three?}/{four?}/{five?} |                      | App\Http\Controllers\Auth\PasswordController@postEmail     | guest      |
|        | POST                           | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} |                      | App\Http\Controllers\Auth\PasswordController@postReset     | guest      |
|        | GET|HEAD                       | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} |                      | App\Http\Controllers\Auth\PasswordController@getReset      | guest      |
|        | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing}                                   |                      | App\Http\Controllers\Auth\PasswordController@missingMethod | guest      |
|        | GET|HEAD                       | {slug?}                                               |                      | App\Http\Controllers\ArticleController@show                |            |
+--------+--------------------------------+-------------------------------------------------------+----------------------+------------------------------------------------------------+-------------

所以简而言之,我希望在网址的根目录中插入slu,但是,我想“排除”某些路由以将其保留在系统本身。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

对于进一步的要求,我已经解决了在routes.php

开头添加此规则的问题
Route::get('home', 'HomeController@index');

此外,@ StuartWagner说清除routes.php应该是空的,这根本不是真的路线,一旦清除routes.php这就是php artisan route:list告诉我的:

+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
| Domain | Method                         | URI                                                   | Name | Action                                                     | Middleware |
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
|        | POST                           | auth/login/{one?}/{two?}/{three?}/{four?}/{five?}     |      | App\Http\Controllers\Auth\AuthController@postLogin         | guest      |
|        | GET|HEAD                       | auth/login/{one?}/{two?}/{three?}/{four?}/{five?}     |      | App\Http\Controllers\Auth\AuthController@getLogin          | guest      |
|        | GET|HEAD                       | auth/logout/{one?}/{two?}/{three?}/{four?}/{five?}    |      | App\Http\Controllers\Auth\AuthController@getLogout         |            |
|        | GET|HEAD                       | auth/register/{one?}/{two?}/{three?}/{four?}/{five?}  |      | App\Http\Controllers\Auth\AuthController@getRegister       | guest      |
|        | POST                           | auth/register/{one?}/{two?}/{three?}/{four?}/{five?}  |      | App\Http\Controllers\Auth\AuthController@postRegister      | guest      |
|        | GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing}                                       |      | App\Http\Controllers\Auth\AuthController@missingMethod     | guest      |
|        | GET|HEAD                       | home                                                  |      | \Bestmomo\Scafold\Http\Controllers\HomeController@index    | auth       |
|        | POST                           | password/email/{one?}/{two?}/{three?}/{four?}/{five?} |      | App\Http\Controllers\Auth\PasswordController@postEmail     | guest      |
|        | GET|HEAD                       | password/email/{one?}/{two?}/{three?}/{four?}/{five?} |      | App\Http\Controllers\Auth\PasswordController@getEmail      | guest      |
|        | POST                           | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} |      | App\Http\Controllers\Auth\PasswordController@postReset     | guest      |
|        | GET|HEAD                       | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} |      | App\Http\Controllers\Auth\PasswordController@getReset      | guest      |
|        | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing}                                   |      | App\Http\Controllers\Auth\PasswordController@missingMethod | guest      |
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+

在某些地方宣布这条路线为“家”。

希望这有助于任何人。

干杯。