Ad

Route For Single Post With OctoberCMS

- 1 answer

I have created route to show all posts on my page like this:

Route::get('posts', function() {
  $posts = Post::with(['image','category'])->get();
  return $posts;
});

How do I create route to show just single post based on its ID? Thank you in advance

Ad

Answer

Try this

Route::get('posts/{id}', function($id) {
    $posts = Post::with(['image','category'])->where('id', $id)->get();
    return $posts;
});
Ad
source: stackoverflow.com
Ad