laravel - MySQL - Combine this into one Query in Eloquent? -


given following schemas:

user    - id    - username  friends    - user_id    - friend_id  places    - id    - name  place_user    - user_id    - place_id 

users have manytomany relationship via friends pivot.

places have manytomany relationships users via place_user

how places associated user , user's friends?

assuming we're working user 1, in raw sql, can places associated user's friends:

select places.place places inner join place_user on place_user.place_id = places.id inner join friends on friends.friend_id = place_user.user_id inner join users on users.id = place_user.user_id friends.user_id = 1 

and can places associated user:

select places.place places left join place_user on place_user.place_id = places.id left join users on users.id = place_user.user_id users.id = 1 

but how can combine 1 query, , moreover, using eloquent?

edit: union of these 2 queries, wondering if there's more succinct, , perhaps less verbose in eloquent


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -