在显示和创建路线之间有所不同

时间:2017-01-06 18:56:17

标签: php laravel routes

我有所有这些路线:

Route::resource('tournaments', 'TournamentController');

在TournamentController中,我有:

public function __construct()
{
    $this->middleware('auth')->except('show');
}

但是当我去http://laravel.dev/tournaments/create时,Laravel认为create是锦标赛slug(如http://laravel.dev/tournaments/my-tournament/)并将我发送给@show而不是@create。

在这种情况下,我从SubstituteBindings Middleware获得了一个未找到的模型......

我真的不明白这一点,我怎么能避免这种混乱?

编辑:我的路线列表:

POST      | tournaments                                                                   | tournaments.store          | App\Http\Controllers\TournamentController@store                            | web,ownTournament,auth          |
GET|HEAD  | tournaments                                                                   | tournaments.index          | App\Http\Controllers\TournamentController@index                            | web,auth                        |
GET|HEAD  | tournaments/create                                                            | tournaments.create         | App\Http\Controllers\TournamentController@create                           | web,ownTournament,auth          |
GET|HEAD  | tournaments/deleted                                                           |                            | App\Http\Controllers\TournamentController@getDeleted                       | web,ownTournament,auth          |
GET|HEAD  | tournaments/{tournament}                                                      | tournaments.show           | App\Http\Controllers\TournamentController@show                             | web                             |
PUT|PATCH | tournaments/{tournament}                                                      | tournaments.update         | App\Http\Controllers\TournamentController@update                           | web,ownTournament,auth          |
DELETE    | tournaments/{tournament}                                                      | tournaments.destroy        | App\Http\Controllers\TournamentController@destroy                          | web,ownTournament,auth          |
GET|HEAD  | tournaments/{tournament}/edit                                                 | tournaments.edit           | App\Http\Controllers\TournamentController@edit                             | web,ownTournament,auth          |

编辑:现在我对另一条路线也有同样的问题:

Route::get('/tournaments/deleted', 'TournamentController@getDeleted');

我得到了SubstituteBindings Middleware找不到的模型。

我猜Middle正在尝试解决已删除的锦标赛名称......

案件重新开启!

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。我有这条路:

Route::get('tournaments/{tournament}', 'TournamentController@show')->name('tournaments.show'); 

在我的路线文件的开头。

我的坏!我在这里给出了那些得到同样问题的人的答案!