Support the ongoing development of Laravel.io →
Eloquent Validation
Last updated 2 years ago.
0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Mirawinn mirawinn Joined 26 Jun 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.