2017-01-06 15 views
2

我有所有這些路線:使展會之間的差異,並制定路線

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

而在TournamentController,我有:

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

但是當我去http://laravel.dev/tournaments/create,Laravel認爲創造是比賽slu((如http://laravel.dev/tournaments/my-tournament/),併發送給@show而不是@create。

在這種情況下,我得到一個模型未找到從SubstituteBindings中間件來了...

我真的不明白這一個,我怎樣才能避免這種混淆???

編輯:另外我的路線清單:

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

編輯:現在我有另一條路同樣的問題:

Route::get('/tournaments/deleted', '[email protected]'); 

我得到不SubstituteBindings中間件發現了一個模型。

我猜中間是試圖解決刪除,因爲比賽名稱...

案重開!

+0

你在'TournamentController'像對應的方法(** **創建,** **顯示,**編輯** ...) ? – Mihailo

+0

是的,我願意!我有索引,創建,存儲,顯示,編輯,更新,銷燬,以及另外2個 –

+1

您不需要路由名稱! laravel正如你所做的那樣命名它們!嘗試刪除它們並再次測試 –

回答

0

我發現了這個問題。 我有這個路線

Route::get('tournaments/{tournament}', '[email protected]')->name('tournaments.show'); 

在我的路由文件的開頭..

我的壞!我爲那些遇到同樣問題的人們回答了這個問題!

的Tx大家對你的忠告,幫助我解決了