A
A
Analka2020-01-15 15:50:10
MySQL
Analka, 2020-01-15 15:50:10

Output Laravel + MySql matches?

How to display matches for the user -user_i = 1. You need to display users who were liked by user 1 and those users who liked this user.
5e1f0a50a5951133487521.png
For example, user 12 matches the condition, but I don’t know how to display it

$users = DB::table('likes')
            ->leftJoin('users','users.id','=','likes.like_user')
            ->leftJoin('user_attributes','user_attributes.user_id','=','likes.like_user')
            ->select('user_attributes.fullname','user_attributes.avatar','user_attributes.country','user_attributes.city','user_attributes.age',
                'users.name','users.id','likes.created_at')
            ->where('likes.like_user','=', 'likes.user_id')
            ->where('likes.user_id','=', Auth::user()->id)
            ->paginate(15);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2020-01-15
@BorisKorobkov

SELECT
  likes_mutual.user_id
FROM
  likes,
  likes AS likes_mutual
WHERE	
  likes.user_id = likes_mutual.like_user
  AND likes_mutual.user_id = likes.like_user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question