我有以下类作为模型:
class WorkOrder extends Model {
protected $connection = 'qcmms-epdevl';
protected $primaryKey = "workorder-id";
public $table = "PUB.pm-work-card";
public function jobs(){
return $this->hasMany('pm-work-job', 'workorder-id', 'workorder-id');
}
}
class WorkJobs extends model {
protected $connection = 'qcmms-epdevl';
protected $table = "PUB.pm-work-job";
protected $primaryKey = "workjob-id";
}
(*) There is a field "workorder-id" in this table.
WorkorderController如下:
class WorkorderController extends Controller {
private $repo;
public function __construct(WorkOrderRepository $repo)
{
$this->repo = $repo;
}
public function artisan()
{
$workorders = $this->repo->getArtisanRecords();
foreach ($workorders as $workorder){
$data = array($workorder->jobs);
app('debugbar')->warning($data);
}
}
}
WorkorderRepository是这样的:
class WorkOrderRepository
{
public function __construct(WorkOrderModel $workOrderModel)
{
$this->model = $workOrderModel;
}
public function getArtisanRecords()
{
$user = \Auth::user()->getAttribute('emp-id');
return ($this->model->select(
'pm-work-card.wo-number',
'pm-work-card.wo-initial-date',
'pm-work-card.emp-id',
'pm-work-card.workorder-id',
'pm-assets.asset-no',
'pm-assets.asset-desc',
'pm-employee.emp-name',
'pm-employee.emp-surname',
'sys-code.cde-desc',
'pm-work-spares.qty-used'
)
->join('PUB.' . 'pm-assets' , function($join)
{
$join->on('pm-assets.asset-number-id', '=', 'pm-work-card.asset-number-id');
})
->leftjoin('PUB.' . 'pm-employee' , function($join2)
{
$join2->on('pm-employee.emp-id', '=', 'pm-work-card.emp-id')
;
})
->join('PUB.' . 'sys-code' , function($join3)
{
$join3->on('pm-work-card.wo-status', '=', 'sys-code.tab-cde')
->where('sys-code.tab-no', '=', 9300);
})
->leftjoin('PUB.' . 'pm-work-spares' , function($join4)
{
$join4->on('pm-work-spares.workorder-id', '=', 'pm-work-card.workorder-id')
;
})
->where('pm-work-card.emp-id', '=', $user)
->where(function($query){
$query->where('pm-work-card.wo-status', '=', 'O')
->orwhere('pm-work-card.wo-status', '=', 'S');
})
->orderBy('wo-number', 'desc')
->get());
}
我遇到的问题是$ data返回null数组,而$ workorders返回控制器中的所有正确数据。
我需要这个(移动能力)才能在没有将字段重新映射到Laravel规范的情况下工作,因为已经部署了应用程序。(使用破折号而不是下划线)
我是Laravel&的新手。 PHP和任何帮助将不胜感激。