Answer the question
In order to leave comments, you need to log in
Probably a difficult question,) Please tell me how to change this request into elequent?
SELECT posts.*, users.name,
COUNT(comments.id) count_comments FROM posts
LEFT JOIN users ON users.id = posts.author_id
LEFT JOIN comments ON comments.post_id = posts.id
GROUP BY posts.id
Answer the question
In order to leave comments, you need to log in
First you need to create models.
https://laravel.com/docs/8.x/eloquent
Describe for relationship models
https://laravel.com/docs/8.x/eloquent-relationships
and then make requests.
Are you sure that you need exactly eloquent (i.e. work with models)? Maybe it will be enough to use query builder https://laravel.com/docs/8.x/queries#introduction ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question