mercredi 7 novembre 2018

Getting the parent and all sub parent of a newly registered user using Laravel

Sample data:

    id |    name       | referBy
  ----------------------------
    1       admin123       0
    2       king           1
    3       omer123        1
    4       bobb123        3
    5       map1233        3

I created a function in my web application wherein users can refer other people to register.

Here is a sample image of what it looks like: enter image description here

if user map1233 will refer another user, it will be placed under him. What i want is to get the parent of the parent of the parent and so on until it goes to the main parent which is admin123..

So if map1233 will refer a user i want to get map1233, omer123 and admin123.

I was able to do that using multiple queries and if statement but the problem with that is there is a limitation of what it can reach. For example, i created 5 queries i can only get to the 5th level. What i want is to get all to all levels. Is there any way to do that using Laravel? Any Help would be appreciated. Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire