Skip to content
Advertisement

Error in showing laravel data to blade using eloquent

I have this Contractor Model

JavaScript

And ContractorDetails Model

JavaScript

I can retrieve all columns under the Contractors Model, but whenever I do this $contractors->ContractorDetails->id, it will show this error “Trying to get property ‘id’ of non-object” . however when I just use this $contractors->ContractorDetails, it is able to show this collection {“id”:6,”contractors_id”:24}

My controller looks like this

JavaScript

My blade file

JavaScript

Any help would be greatly appreciated

Advertisement

Answer

Found a fix.

I create another function under my Contractors Model

JavaScript

Now I can get the ID from the ContractorDetails Model with this

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement