phplaravellaravel-4eloquenttinder

Tinder Laravel matching between 2 models


i have 2 tables namely users and employers . I would like to match them together like tinder style, which means that when both the user and the employer liked each other , they will each receive a notification .

However i am not sure how would the relationship table will look like??

Right now what i have is in the Relationship Table ,

1.user_id

2.target_employer_id

3.employer_id

4.target_user_id

If i am not wrong , this is considered as a Many - Many relationship. So , is this table correct???


Solution

  • As I understand your question, in your application, a user can like an employer, and an employer can like a user.

    If this is right, it seems clear to me that there are two distinct (many to many) relationships (user => employer, employer => user), and that in your proposed table only two fields are filled at a time.

    The best way to represent those relationships is to use two tables.

    User to employer fields:

    1. user_id
    2. target_employer_id

    Employer to user fields:

    1. employer_id
    2. target_user_id

    Depending if you are using Laravel 4 or Laravel 5, you can use one of those two packages to generate the two pivot tables via a migration:

    https://github.com/JeffreyWay/Laravel-4-Generators

    https://github.com/laracasts/Laravel-5-Generators-Extended