【问题标题】: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;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      • 2023-03-18
      • 2016-05-22
      • 2017-09-27
      • 2019-04-01
      • 2018-02-28
      相关资源
      最近更新 更多