In my laravel application, I’m trying to display some records on my blade.
Following is my Controller function related to this issue.
JavaScript
x
public function show($id)
{
$vrs = SampleRegistration::latest()->where('id','=',$id)->first();
$trs = TestResult::all()->where('test_id','=',$id);
//dd($trs);
return view('viewresults.show',compact('vrs','trs'));
}
And I’m trying to display those data on my blade, following is my blade part.
JavaScript
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
@foreach ($trs as $key => $tr)
<strong>{{ $tr->test_type }}</strong>
{{ $tr->test_result }}
@endforeach
</div>
</div>
But now the issue is with,
JavaScript
$trs = TestResult::all()->where('test_id','=',$id);
This can have 1 or more results.
But, even though it has more results, every time this will display only one result on my blade.
And any of the time it won’t display the
JavaScript
<strong>{{ $tr->test_type }}</strong>
But when I DD
it shows me all the results…
Advertisement
Answer
I found an answer for this, I just changed my query into this
JavaScript
$trs =DB::table('test_results')
->where('test_id','=',$id)
->get();
and now It displays all the records, still have no idea why the previous
JavaScript
$trs = TestResult::all()->where('test_id','=',$id);
was failing.