【问题标题】:Route for single post with OctoberCMS使用十月CMS的单个帖子的路线
【发布时间】:2020-03-19 12:47:36
【问题描述】:
我已经创建了在我的页面上显示所有帖子的路线,如下所示:
Route::get('posts', function() {
$posts = Post::with(['image','category'])->get();
return $posts;
});
如何创建路由以根据其 ID 仅显示单个帖子?
提前谢谢你
【问题讨论】:
标签:
laravel
routes
octobercms
【解决方案1】:
试试这个
Route::get('posts/{id}', function($id) {
$posts = Post::with(['image','category'])->where('id', $id)->get();
return $posts;
});
【解决方案2】:
你可以在路由中使用 pass id 参数:
Route::get('posts/{id}', function($id) {
$posts = Post::with(['image','category'])->where('id', $id)->get();
return $posts;
});