Mirawinn said:
I'm trying to access an attribute of a nested object:
$company->order()->first()->customer()->first()->name
Company hasmany orders, orders hasone customer. Works fine except when there is no customer attached to an order as an example, then it throws: Call to a member function xxxxx() on a non-object
Is there a way to validate that these are correctly linked up without having to write a separate validation function for each field I need? This is a database that I did not design and cannot restructure with thousands of different fields some only reachable by 4+ levels of nesting.
Thanks in advance!
I have a similar issue on this but in relation to JSON request. I still can't get it to make it works for accessing the nested object. In my case, $data = $request->json()->all(); $coach_uuid = $data->coach()->uuid; --> it didn't work
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community