我通常正确地配置了我的路线:
Route::get('/news/', 'PagesController@news');
Route::get('/news/{id}', 'PagesController@newsDetail');
在我的PagesController中,我还创建了两个传递给视图的变量:
$relatedOlder = (
News::where('created_at', '<', $currentPostDate)
->orderBy('created_at', 'desc')->value('created_at') != '') ?
News::where('created_at', '<', $currentPostDate)
->orderBy('created_at', 'desc')->firstOrFail() :
News::where('created_at', '>', $currentPostDate)
->orderBy('created_at', 'asc')->skip(1)->take(2)->firstOrFail();
$relatedNewer = (
News::where('created_at', '>', $currentPostDate)
->orderBy('created_at', 'asc')->value('created_at') != '') ?
News::where('created_at', '>', $currentPostDate)
->orderBy('created_at', 'asc')->firstOrFail() :
News::where('created_at', '<', $currentPostDate)
->orderBy('created_at', 'desc')->skip(1)->take(2)->firstOrFail();
在localhost上,一切都运行正常,但是在我转到404 error
后,这两个变量在线给我/news/{id-of-my-post}
如果我没有通过我的观点,那么这些变量就可以了。我的查询似乎是正确的,但我不明白它是否可能是服务器/缓存问题或其他什么。
有什么想法吗?