无法从另一个表中获取数据,我不知道为什么
@if(count($shift))
@foreach($shift as $data)
<tr>
<td>{{$data->serial}}</td>
<td>{{$data->date}}</td>
<td>{{$data->startshift}}</td>
<td>{{$data->endshift}}</td>
@foreach($tracking as $track)
<!--here is the problem-->
@endforeach
@endforeach
</tr>
$shift = DB::table('employee_schedule')
->select('id','user_id as user_id','serial as serial','date as date','startshift as startshift','endshift as endshift')
->orderBy('id','ASC')
->paginate(5);
$tracking = DB::table('empsheduling')
->select('serial as serial','date as date','startshift as startshift','endshift as endshift','Hourswork as Hourswork')
->first();
return view('shifTracker.viewshifTracker',compact('shift','tracking'));
您已选择了第一个empsheduling表记录,请查看查询的结尾:first()
。
要么用first()
替换get()
,要么在你的视图中删除循环并用$tracking->data
获取数据。
我已经通过将first()更改为get()来找到解决方案。谢谢