title: laravel view composer - send foreach data to view blade
body: <p>ok been messing with this for a few hours now, just can't seem to figure it out. I am collecting data from certain users, then I want print out all the data and send it to the view blade for each user.  </p>
  
  <p>my code so far</p>
  
  <pre><code>        view()-&gt;composer('dashboard.index', function (View $view) {
          $currency = Config::whereKey('currency')-&gt;first()-&gt;value;
          $user = auth()-&gt;user();
  
          $users = User::select('id','name','type','pay_rate','country_id')
          -&gt;where('type', '=', 'country_manager')
          -&gt;orderBy('country_id','ASC')
          -&gt;get();
  
          if($users) {
             foreach ($users as $u) {
              $uid = $u-&gt;id;
              $name = $u-&gt;name;
              $type = $u-&gt;type;
              $pay = $u-&gt;pay_rate;
              $countryid = $u-&gt;country_id;
  
              if($type == 'country_manager'){ $role = 'Country Manager'; }
              if($type == 'team_leader'){ $role = 'Team Leader'; }
              if($type == 'moderator'){ $role = 'Moderator'; }
              if($type == 'suspend'){ $role = 'Suspended'; }    
  
              $sent = '0';
              $reply = '0';
              $earn = '0';
  
              $data = '&lt;div class="divTableCell"&gt;'.$name.'&lt;/div&gt;
              &lt;div class="divTableCell"&gt;'.$countryid.'&lt;/div&gt;
              &lt;div class="divTableCell"&gt;'.$role.'&lt;/div&gt;
              &lt;div class="divTableCell"&gt;'.$pay.' '.$currency.'&lt;/div&gt;
              &lt;div class="divTableCell"&gt;'.$sent.'&lt;/div&gt;
              &lt;div class="divTableCell"&gt;'.$reply.'&lt;/div&gt;
              &lt;div class="divTableCell"&gt;'.$earn.' '.$currency.'&lt;/div&gt;';
  
  
              }
          }
  
      $view-&gt;with(compact('data'));
  
      });
  </code></pre>
  
  <p>I know the data is collecting correctly, but just do not know how to print it view page from the view composer script. </p>