jeudi 28 novembre 2019

How to pass nested foreach from laravel controller to view on blade

**

how to pass the value to laravel blade view in from every nested foreach loop

How to pass nested foreach from laravel controller to view on blade for a tree structure based in three levels based on the referende_id on the above code i have fetched the three levels and now i would like to pass the value to the blade in laravel can anyone help me to sort out this..
class ClientController extends Controller { public function index($reference_id){

          $clients = table1::leftjoin('table2', function($join) {
              $join->on('table2.user_id', '=', 'table1.id');
          })->where('table1.reference_id','=',$reference_id)->get();

            foreach($clients as $levelOne)
          {//here $row is the current $data's collection 
              $clientsLevelOne = table1::leftjoin('table2', function($join) {
                  $join->on('table2.user_id', '=', 'table1.id');
              })->where('table1.under_reference','=',$levelOne->reference_id)->get();

              //$clientsLevelOne = arrayName["levelOne"];
              //$variable_name['one'] = value;

              $datas = array($clientsLevelOne);

              foreach ($datas as $items) 
              {   
                  //echo 'LEVEL ONE:<br><br>';
                  foreach ($items as $values){                    
                      $LevelOne =  $values;                                                                                   
                      //echo $LevelOne.'<br><br>';
                  }
              }

              //return $LevelOne;

              foreach ($datas as $items) 
              {   //echo '<br>LEVEL TWO:<br><br>';
                  foreach ($items as $values){                                            
                      $levelTwo = $values['reference_id'];    
                      $clientsLevelTwo = table1::leftjoin('table2', function($join) {
                          $join->on('table2.user_id', '=', 'table1.id');
                      })->where('table1.under_reference','=',$levelTwo)->get();

                      //dump($clientsLevelTwo);

                      $LevelDatas = array($clientsLevelTwo);

                      //$LevelDatas = array_merge($LevelTwo);
                      //print_r($LevelDatas);
                      //echo '<br>LEVEL TWO:<br><br>';

                      foreach($LevelDatas as $two)
                      {                       
                          foreach ($two as $values)
                          {
                              $levelThree =  $values;                             
                          }
                      }
                  }
              }

              foreach ($datas as $items) 
              {   //echo '<br>LEVEL THREE:<br><br>';
                  foreach ($items as $values){                                            
                      $levelThree = $values['reference_id'];  
                      $clientsLevelThree = table1::leftjoin('table2', function($join) {
                          $join->on('table2.user_id', '=', 'table1.id');
                      })->where('table1.under_reference','=',$levelThree)->get();

                      $LevelDatas = array($clientsLevelThree);

                      foreach($LevelDatas as $two)
                      {                       
                          foreach ($two as $values)
                          {
                              $levelDatasThree =  $values['reference_id'];    
                              $clientsLevelDatasThree = table1::leftjoin('table2', function($join) {
                                  $join->on('table2.user_id', '=', 'table1.id');
                              })->where('table1.under_reference','=',$levelDatasThree)->get();

                              $ThreeDatas = array($clientsLevelDatasThree);

                              foreach($ThreeDatas as $three)
                              {                       
                                  foreach ($three as $values)
                                  {
                                      $levelThreeDatas =  $values;    
                                  }}}}}}}           


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

Aucun commentaire:

Enregistrer un commentaire