【发布时间】:2021-06-30 01:15:06
【问题描述】:
这是我的雄辩关系-
public function owner()
{
return $this->hasOne(Owner::class, 'owner', 'owner_name');
}
当我访问完整对象时-
{{ $dealer->owner }}
我得到了对象
{
"id": 11087,
"office_name": "BHILWARA DTO ( RJ-6 )",
"registration_number": "RJ06VS2840",
"chasis_number": "MBLHAR076J4K00280",
"owner": "GANESH LAL",
"father_name": "KASTUR KUMAWAT",
"address": "THALARAIPUR",
"vehicle_class": "M-Cycle\/Scooter",
"insurance_type": "COMPREHENSIVE",
"insurance_company_name": "TATA AIG GENERAL INSURANCE CO. LTD.",
"insurance_from": "2018-11-08",
"insurance_up_to": "2019-11-07",
"policy_number": "0189518728",
"created_at": null,
"updated_at": null
}
但是当我尝试从对象访问单个属性时 -
{{ $dealer->owner->office_name }}
我收到错误
试图获取非对象的属性“office_name”
【问题讨论】:
-
我最好的猜测是
$dealer在 foreach 中,其中一个没有所有者 -
那我该怎么办?
-
可能有经销商在数据库中缺少所有者。
标签: javascript php json laravel eloquent