Patrick Obafemi Patrick Obafemi - 1 month ago 9
PHP Question

laravel calling a function inside another function

i just want to know how i would include a function inside another function. TRying to query my database for users 3 levels deep.

<?php

namespace App\Repositories\Referrals;

use Auth;

/**
*
*/
class EloquentReferrals implements ReferralRepository
{

function __construct(User $model)
{
return $this->model->all();
}


function __construct(User $model)
{
return $this->model->all();
}

public function getallreferrals()
{
return $this->model->where('referred_by', Auth::user()->referral_id)->get();
}

public function getallreferrals2gen()
{

}

public function getallreferrals3gen(){

}

public function getallreferralsbyID($id){

}

public function getallreferrals2gen($id){

}

public function getallreferrals3gen($id){

}


}


in my repository the get all referrals function returns all direct referrals. I want to use the result to get the referrals of those referrals. How do i include it inside my getallreferrals2gen function?

Answer Source

use $this to call a function from a function in the same class;

property, like so;

public function getallreferrals()
{
    return $this->model->where('referred_by', Auth::user()->referral_id)->get();
}

public function getallreferrals2gen()
{
     $this->getallreferrals()(
}