0

I have this sql query which works fine, how can i write this in eloquent( eager loading) using relationships, not joins.

SELECT ads.id,ads.name,u.name,country_translates.name,city_translate.name,category_translates.name
    FROM ads
    INNER JOIN users u ON ads.user_id = u.id
    INNER JOIN cities ON ads.city_id = cities.id
    INNER JOIN country_translates ON cities.country_id = country_translates.country_id
    INNER JOIN city_translate ON ads.city_id = city_translate.city_id
    INNER JOIN category_translates ON ads.category_id = category_translates.category_id
    WHERE country_translates.language_id = 2 AND city_translate.language_id = 2 AND category_translates.language_id = 2
3
  • if you joins are all relations and are set up correctly, you could use whereHas : laravel.com/docs/5.8/… Commented Dec 9, 2019 at 17:07
  • stackoverflow.com/questions/22842977/… Commented Dec 9, 2019 at 17:08
  • Could you please post the models you are using. It would be impossible to answer this without seeing relationship and model names. Also have you tried to write this in eloquent? Commented Dec 9, 2019 at 18:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.