O
O
olux2021-03-14 14:25:48
SQL
olux, 2021-03-14 14:25:48

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

1 answer(s)
A
Antonio Solo, 2021-03-14
@solotony

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 question

Ask a Question

731 491 924 answers to any question