jeudi 13 septembre 2018

Laravel many to many relation get all childrens and children of childrens

I have a many to many relation on my User model and I try to pickup all children and grandchildren elements of a user with the following recursive function

    public function hasreceivers()
    {
        return $this->belongsToMany('App\User', 'reporting_to', 'acc_reporting_to_id', 'acc_receiving_from_id')
            ->where('account_status', 'A');
    }


    public function hasreceivers_rec()
    {
        return $this->hasreceivers()->with(['hasreceivers_rec']);
    }

but when I query for the relation

$oUser = \App\User::with('hasreceivers_rec')->where('account_id', $acc_id)->first();

Practically I would like to get all the user ID's which are childrens of a requested User.

I get server timeout.

How do I build correctly this kind of eloquent queries?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NDOA64
via IFTTT

Aucun commentaire:

Enregistrer un commentaire