I have a problem regarding the return view('doctor_index', compact('result') on my contoller
here is my controller
public function index()
{
$data = Auth::user()->patient;
$data = explode(',', $data);
foreach ($data as $key => $datas) {
$result = DB::table('patients')->where('id', $datas)->get();
foreach ($result as $key => $res) {
$output = ' <h4><b>'. $res->patient_name .'</b></h4>
</p>Birthday: <strong>'. $res->post_date .'</strong> Age: <strong>'. $res->patients_age .'</strong></p>
<p>Address: <strong>'. $res->patient_address .'</strong></p><br><br>';
}
echo $output;
// return view('doctor_index', compact('output'));
}
}
at first i used echo $output; this is what it displayed
Output of echo $output:

Now if i use the return view on the controller it displays
Output of the return view:

as you can see when i use the return view it only display the first element
My question is how can i display all of the elements to my view using the return view
my view code:
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-body">
<div class="col-md-12">
<h2><b>{{ Auth::user()->name }} </b></h2>
<p>Email: <strong> {{ Auth::user()->email }} </strong></p>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
<div class="col-md-12">
<h3>Patients</h3>
</div>
<div class="col-md-12">
<div class="container">
<?php echo $output ?>
</div>
</div>
</div>
</div>
</div>