title: How to display the array element to view
body: <p>I have a problem regarding the return view('doctor_index', compact('result') on my contoller</p>
  
  <p>here is my controller</p>
  
  <pre><code>public function index()
  {
  
      $data = Auth::user()-&gt;patient;
  
      $data = explode(',', $data);
  
      foreach ($data as $key =&gt; $datas) {
  
         $result = DB::table('patients')-&gt;where('id', $datas)-&gt;get();
  
              foreach ($result as $key =&gt; $res) {
  
                  $output = ' &lt;h4&gt;&lt;b&gt;'. $res-&gt;patient_name .'&lt;/b&gt;&lt;/h4&gt;
                                  &lt;/p&gt;Birthday: &lt;strong&gt;'. $res-&gt;post_date .'&lt;/strong&gt;  Age: &lt;strong&gt;'. $res-&gt;patients_age .'&lt;/strong&gt;&lt;/p&gt;
                                  &lt;p&gt;Address: &lt;strong&gt;'. $res-&gt;patient_address .'&lt;/strong&gt;&lt;/p&gt;&lt;br&gt;&lt;br&gt;';
              }  
  
           echo $output;
  
          // return view('doctor_index', compact('output'));
      }
  }
  </code></pre>
  
  <p>at first i used echo $output; this is what it displayed</p>
  
  <p><strong>Output of echo $output:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/ckE6J.jpg" alt="output of echo $output"></p>
  
  <p>Now if i use the return view on the controller it displays</p>
  
  <p><strong>Output of the return view:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/8T25q.jpg" alt="output of the return view"></p>
  
  <p>as you can see when i use the return view it only display the first element</p>
  
  <p>My question is how can i display all of the elements to my view using the return view </p>
  
  <p>my view code:</p>
  
  <pre><code>&lt;div class="col-md-8 col-md-offset-2"&gt;
          &lt;div class="panel panel-default"&gt;
              &lt;div class="panel-body"&gt;
  
                  &lt;div class="col-md-12"&gt;
                      &lt;h2&gt;&lt;b&gt;{{ Auth::user()-&gt;name }} &lt;/b&gt;&lt;/h2&gt;
                        &lt;p&gt;Email: &lt;strong&gt; {{ Auth::user()-&gt;email }} &lt;/strong&gt;&lt;/p&gt; 
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="panel panel-default"&gt;
              &lt;div class="panel-body"&gt;
  
                  &lt;div class="col-md-12"&gt;
                      &lt;h3&gt;Patients&lt;/h3&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;div class="container"&gt;
  
                             &lt;?php echo $output ?&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>