laravel - 如何使用 HasMany 显示数据数据表 Laravel
问题描述
这是我的控制器我想显示数据循环但是当它显示时只出现一个问题在哪里,请帮助,并给我解决这个问题的解决方案
if(empty($search)){
$jobData = SrvJobSop::with('getJobSopFileMap')
->limit($limit)
->orderBy($order, $dir)
->get();
}else{
$jobData = SrvJobSop::where('name', 'LIKE',"%{$search}%")
->offset($start)
->limit($limit)
->orderBy($order,$dir)
->get();
$totalFiltered = SrvJobSop::where('name', 'LIKE',"%{$search}%")
->count();
}
$data = [];
if(count($jobData) > 0){
foreach($jobData as $num => $jobsop){
$currentData = [];
$currentData['no'] = $num+1;
$currentData['sop_code'] = $jobsop->sop_code;
$currentData['name'] = $jobsop->name;
$currentData['vehicle_brand_id'] = $jobsop->getVehicleBrand->name;
$currentData['vehicle_model_id'] = $jobsop->getVehicleModel->name;
$currentData['vehicle_type_id'] = $jobsop->getVehicleType->name;
$currentData['year_id'] = $jobsop->getYear->name;
foreach($jobsop->getJobSopFileMap as $p){
$currentData['file'] = $p->file;
}
$currentData['machine_type_id'] = $jobsop->getMachineType->name;
$currentData['machine_type_id'] = $jobsop->getMachineType->name;
$currentData['created_at'] = date('d F Y h:m:s',strtotime($jobsop->created_at));
$currentData['created_by_user_id'] = $jobsop->getCreatedByUserId->name;
$currentData['opsi'] = "
<a href=".url('/carfix-workshop-operation-module/job-sop/form?id='.encrypt($jobsop->srv_job_sop_id)).". class='btn btn-success btn-xs fa fa-pencil-square-o'
title='Edit Data'></a>
<a onclick=deleteData('".encrypt($jobsop->srv_job_sop_id)."') class='btn btn-danger btn-xs fa fa-trash-o'
title='Delete Data'></a>";
$data[] = $currentData;
}[enter image description here][1]
}
我想循环文件名怎么做,我的代码对吗?
解决方案
推荐阅读
- c++ - 包含 std 集合迭代器的模板
- javascript - 模态被隐藏,但模态的“历史”被保留
- reactjs - 在反应中使用 classList 添加和删除时遇到问题
- jenkins - 我们可以将 Jenkins 中凭证的使用仅限于某些用户吗?
- c++ - 具有灵活大小结构的新数组分配?
- azure-media-services - Azure 媒体服务 JobState 不再是枚举
- javascript - 使用 Promise 从后台脚本返回地图
- firebase - 通过 firebase 更改字符串变量
- ms-access - 在 Access 2016 字段中发布 $0.00 的结果
- c# - 合并通用枚举的标志