Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dioscures's avatar

Eloquent Users-Matches-Blocked Tinder App

Hi, I create a website like Tinder, and I made the "matches managements" and the "blockage of user"... But, I can not join them.

The site have 3 tables : users (table of users), matches (table of crushs) ,blockages (table of users blocked)

  • users(id, name, email)
  • matches(id, user_id_from, user_id_to, accepted) / user_id_from + user_id_to foreign key to table users
  • blockages(id, user_id_from, user_id_to) / user_id_from + user_id_to foreign key to table users

In model User :

public function matchesOfMine(){
return $this->belongsToMany('App\Models\User', 'matches', 'user_id_from', 'user_id_to');
}
public function matchOf(){
return $this->belongsToMany('App\Models\User', 'matches', 'user_id_to', 'user_id_from');
}
public function matches(){
return $this->matchesOfMine()->wherePivot('accepted', true)->get()->merge($this->matchOf()->wherePivot('accepted', true)->get());
}
public function blockagesOfMine(){
return $this->belongsToMany('App\Models\User', 'blockages', 'user_id_from', 'user_id_to');
}
public function blockingOf(){
return $this->belongsToMany('App\Models\User', 'blockages', 'user_id_to', 'user_id_from');
}
public function blockages(){
return $this->blockagesOfMine()->get() ->merge($this->blockingOf()->get());
}

With theses codes, I can list all my crushes and all my users blocked. But, I would like to list all my crushes without users blocked... because if I blocked users, they should be in the matches...

Do you have an idea to do that? Thanks you in advance, Quentin

0 likes
1 reply

Please or to participate in this conversation.