2021年4月3日星期六

Laravel Eloquent relationship return Trying to get property 'office_name' of non-object

This is my Eloquent Relation -

public function owner()  {      return $this->hasOne(Owner::class, 'owner', 'owner_name');  }  

And here when I access full object -

  

I get the object

{      "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  }  

but when I try to access single property from the object -

  

I get error

Trying to get property 'office_name' of non-object

https://stackoverflow.com/questions/66931627/laravel-eloquent-relationship-return-trying-to-get-property-office-name-of-non April 03, 2021 at 09:21PM

没有评论:

发表评论