Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mehmetanbaki's avatar

how to get comments and ratings of post in one api route

i have three tables posts, ratings and comments just want to get all the comments and ratings of first post in single API route

0 likes
2 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

Assuming you have Post Comment and Rating Models, and relationships between

Post::with(['comments', 'ratings'])->get();
Sergiu17's avatar

You could create a separate folder for controllers related to API App\Http\Controllers\API\PostsController.php

and in your api.php define your route

Please or to participate in this conversation.