2017-07-17 54 views
1

當我使用像這樣我的路線,該路線test工作正常。
路線: -Laravel航線資源打破了另一條路線

Route::group(array('namespace' => '\User'), function() { 
Route::get('user/my-favorite','[email protected]'); 
Route::get('user/test','[email protected]'); // is working 
Route::resource('user', 'UserController'); 
Route::group(['middleware' => ['auth']], function() { 
Route::get('user/planed',['as' => 'user.planed', 'uses' => '[email protected]']); 
. 
. 
. 
. 

但是,當我想用​​它像下面,它顯示了一個空白頁:

Route::group(array('namespace' => '\User'), function() { 
Route::get('user/my-favorite','[email protected]'); 
Route::resource('user', 'UserController'); 
Route::group(['middleware' => ['auth']], function() { 
Route::get('user/planed',['as' => 'user.planed', 'uses' => '[email protected]']); 
Route::get('user/test','[email protected]'); // is not working 
. 
. 
. 
. 

什麼是我的錯?

+1

你是什麼「的意思它不工作?「究竟發生了什麼?我可以看到你在'auth'中間件組中有測試路線,所以也許這就是原因。但是,請再次澄清究竟發生了什麼? –

+0

@AaronFahey'在控制器test'方法打印的查詢輸出:'$用戶=訂戶::其中( 'USER_ID',$這 - > _用戶id) - >動物內臟( 'USER_ID'); DD($用戶);' - 它是把裏面'Auth' middlware路線前後'resource'工作,但顯示一個空白頁後'resource' –

+0

我通過在用戶登錄 –

回答

1

由於測試通話由

Route::resource('user', 'UserController'); 

攔截,因爲如果您在控制檯中的路線與

$> php artisan route:list 

你會看到它包括

GET|HEAD | user/{user} 

和那麼你的第一條路線

Route::get('user/test','[email protected]'); // is not working 

從未達到。嘗試把它放在另一行之前。

+0

你的意思是路線'資源測試它''用戶'應該放在所有'用戶'路線之後?我以爲laravel'Resource'只攔截'index','create','update',.... routes !! –

+0

正如你看到的'用戶/ planed'路由工作,這是後'resource' –

+0

當我使用的路線是這樣的:'路線::獲得(「用戶/測試/(編號)」,「UserController的@測試」 );',它正在工作!爲什麼?我不需要'id'通配符 –

1

我的東西命名的路線檢查問題This

嘗試這樣

Route::group(array('namespace' => '\User'), function() { 
Route::get('user/my-favorite','[email protected]'); 
Route::resource('user', 'UserController'); 
Route::group(['middleware' => ['auth']], function() { 
Route::get('user/planed','[email protected]'])->name('user.planed'); 
Route::get('user/test','[email protected]'); // is not working 

只需更換

Route::get('user/planed',['as' => 'user.planed', 'uses' => '[email protected]']); 

隨着

Route::get('user/planed','[email protected]'])->name('user.planed'); 
+0

試過了,沒有工作。事件是我在'resource'之後放了'test'路由,不工作!沒有錯誤的空白頁面 –

+0

你的'['middleware'=> ['auth']]'工作正常嗎? –

+0

是的,它是在這個中間件的其他路線工作 –