2016-06-19 78 views
2

我有路線問題,我有我的路線:Laravel 5.1 - 路線行不通

Route::get('dashboard/password', '[email protected]'); 

Route::post('dashboard/updatepassword', '[email protected]'); 

// PAGINA UTENTE PUBBLICA 

Route::get('/{username}', '[email protected]'); 


// blog routes 

    Route::get('blog', '[email protected]'); 
    Route::get('blog/{slug}', '[email protected]'); 
    Route::get('blog/category/{name}', '[email protected]'); 
    Route::get('blog/tag/{name}', '[email protected]'); 

    Route::resource('comment', 'CommentController'); 

和我FrontController:

public function blog() 
    { 

     $articles = Article::OrderBy('id','DESC')->paginate(3); 
     $Allarticles = Article::OrderBy('id','DESC')->get(); 
     $Allcategories = BlogCategory::OrderBy('id','DESC')->get(); 
     $Alltags = Tag::OrderBy('id','DESC')->get(); 
     $Allcomments = Comment::OrderBy('id','DESC')->take(3)->get(); 

     return view('blog', compact('articles','Alltags','Allarticles','Allcategories','Allcomments')); 
    } 

如果我去 「http://localhost:8000/blog」 它返回頁面我之前在哪裏。類似於route-> back()。

我不知道爲什麼我有這個問題,其他博客路線很好。

我做了一些測試這樣的:

public function blog() 
     { 
      return "Hi"; 

     } 

它不返回「你好」,所以,我認爲是路線問題。我在這裏沒有可以使用的中間件,我的其他路線如博客/文章運作良好。

+0

什麼是您的blog.blade.php的完整路徑? 你可能用另一條路線覆蓋路線嗎?嘗試把你的路線放在你的routes.php – bobbybackblech

+0

意見/ blog.blade.php這是完整的路徑,我沒有使用文件夾,我不知道爲什麼,但沒有工作。如果我去一個不存在的路線,我有同樣的問題。 –

+0

問題是:Route :: get('/ {username}','FrontController @ user');我刪除,它的工作 –

回答

0

好,我定一看,問題是:

Route::get('/{username}', '[email protected]'); 

有一些錯誤在這裏,我不知道至極錯誤,也許是路徑,我刪除了這個,它工作正常。

1

你可以發佈你的路線文件的內容? 如果有任何'blog'的路由超出了您發佈的包含參數的路由(例如,Route::get('blog/{blog_post_id}, ...),請嘗試將它們移動到文件中的'blog'以下。

如果不是上述情況,那麼聽起來好像可能有一些緩存在玩弄東西,當我運行我的優化以查看生產環境將如何執行時,它經常捕獲我,而我忘記清除所有的緩存,這是我通常的修復(我有別名,因爲我經常搞砸);

php artisan route:clear 
php artisan view:clear 
php artisan cache:clear (Side note, clears all auth sessions, will require a re-log) 
composer dump-autoload 
php artisan optimize --force 

這將完全清除爲路由,視圖和授權創建的任何緩存。

另外,請檢查您的Laravel日誌和你的Apache/Nginx的日誌同樣也很值得擁有的那些

+0

我更新了與博客相關的所有路線:) –

+0

感謝人,路線文件看起來不錯,嘗試運行這些命令來消除任何緩存,看看是否有幫助。你也可以嘗試重新啓動你的Apache/NginX + MySQL服務 – DLMousey

+0

yes yes tryed!但同樣的問題! –

0

你的問題是路由文件中的模式匹配。看來,路由被分配到與URI匹配的第一條路由。

Route::get('/{username}', '[email protected]'); 
Route::get('blog', '[email protected]'); 

http://localhost:8000/blog比賽這兩個途徑,因爲{username}可能是blog,因此Route::get('/{username}', '[email protected]');將始終使用。

您必須在路線名稱(例如添加更多文字)或更具體的路線順序中更具體。以您希望的方式訂購當前路線的示例如下。

Route::get('dashboard/password', '[email protected]'); 

Route::post('dashboard/updatepassword', '[email protected]'); 

// blog routes 

    Route::get('blog', '[email protected]'); 
    Route::get('blog/{slug}', '[email protected]'); 
    Route::get('blog/category/{name}', '[email protected]'); 
    Route::get('blog/tag/{name}', '[email protected]'); 

    Route::resource('comment', 'CommentController'); 

// PAGINA UTENTE PUBBLICA 

Route::get('{username}', '[email protected]');