to implement a basic relationship system I followed this model suggested from a website:
user_relationship:
------------------
- user_1
- user_2
- status
- user_action
Where user_1
, user_2
, user_action
are foreign keys that references users.id
and user_1 < user_2
to avoid duplicate tuples.
However I'm finding it difficult to write this SQL query in Eloquent (Laravel 5.5):
SELECT user_1, user_2
FROM user_relationships
WHERE (user_1 = :user OR user_2 = :user) AND status = 'friends'
This query should return all the tuples where user is either user_1
or user_2
.
I have a very basic knowledge of Eloquent so I'm having a hard time making this work, but since I've seen many people saying that it's better to use Eloquent whenever possible I'd like to use it.