2017-03-07 34 views
1

我正在試圖使seo友好的網址與郵件的slu make。那麼,到目前爲止,我還做這是我RouteServiceProviderRouteServiceProvider無法找到查詢

這在我BlogController

public function show(Post $post){ 

    return view("blog.show", compact('post')); 
} 

當我去到後http://example.com/slug-from-database我已經得到了錯誤

ModelNotFoundException in Builder.php line 426:

沒有關於型號[App \ Post]的查詢結果。

任何想法,爲什麼我得到這個錯誤?

+0

只是想檢查一下,你有一個叫做模型'Post'與'App \ Post'的命名空間? – Spholt

+0

是的,我有。我也可以發佈它,但我不在這裏與問題有關。 –

+0

我注意到你在服務提供者中指定了一個命名空間,可以試着在'App \ Http \ Controllers \ Post'中找到你的'Post'模型嗎?沒有更多的錯誤輸出,有點難以分辨。這是一個很長的一段時間tbh – Spholt

回答

3

你在你的WHERE條款缺失$slug,在這裏:

Route::bind('post', function($slug){ 
    return Post::published()->where('slug')->first(); 
}); 

改變這樣的查詢,也將努力:

Post::published()->where('slug', $slug)->first();