how to get all user based on where condition and compare this result with another condition in laravel eloquent

Tags: , , , ,



I have a user table

column referred_by:

enter image description here

I have a view for step 1 user like where referred_by=auth::user()->id

In here whoever registered by this user referal link will be shown in this table:

enter image description here

I have another view for step 2

In here whoever was in step 1 if someone register by their referal link their data will show in step 2 view:

enter image description here

Now the problem is in step 2 I can only get one user data which is 101 users all of them registered by this user referral link, but I have one more user who is supposed to be in step 2 view because this user registered by using one of the step 1 user referral link ….but I can’t get these two users all referral user….i can only get one user referal user…

heres my controller code

public function referral_report(){ $referral_report = User::where(‘referred_by’, Auth::user()->id)->orderBy(‘id’, ‘desc’)->paginate(10);

    return view('affiliate.referral_report',compact('referral_report'));
}

 public function referral_report2(){
   
   $referral_reportt =User::where('referred_by', Auth::User()->id)->first();
    
    if($referral_reportt != null){
   $referral_report2 = User::where('referred_by', $referral_reportt->id)->paginate(10);}
 
    return view('affiliate.referral_report2',compact('referral_report2'));
}

Answer

i just used wherein instead of where and get the id’s in array

public function referral_report2(){
   $referral_reportt =User::wherein('referred_by', Auth::User()->id)->get('id')->toarray('id');
 $referral_report2 = User::wherein('referred_by', $referral_reportt)->paginate(10);
 return view('affiliate.referral_report2',compact('referral_report2'));
}


Source: stackoverflow