mardi 14 septembre 2021

How to use loop for following Laravel code?

    $query1 =  User::where('sponser_id',$_SESSION['ruserid'])->get('userid');
    $count1= count($query1);
    
    $query2 =  User::whereIn('sponser_id',$query1)->get('userid');
    $count2= count($query2);

    $query3 =  User::whereIn('sponser_id',$query2)->get('userid');
    $count3= count($query3);

    $query4 =  User::whereIn('sponser_id',$query3)->get('userid');
    $count4= count($query4);

    $query5 =  User::whereIn('sponser_id',$query4)->get('userid');
    $count5= count($query5);

    $query6 =  User::whereIn('sponser_id',$query5)->get('userid');
    $count6= count($query6);

    $query7 =  User::whereIn('sponser_id',$query6)->get('userid');
    $count7= count($query7);

    $allcount=$count1+$count2+$count3+$count4+$count5+$count6+$count7;

I want to calculate the total downlines of users. This code works fine. But How to simplifies this code using a loop?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire