Replies: 1 comment 2 replies
-
Use a custom creation method |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Let's say we have a
Person
model which has manyContactNumber
and each contact number can belong to aBusiness
or aCustomer
which is a nullablemorphTo
relation. The following is the structure of the data classes.Within the
ContactNumberData
I'd like to have a separate key forbusiness
andcustomer
and conditionally populate based on the ownermorphTo
relation.Now from within the
PersonController
, we'll loadpersons.contactNumbers.owner
and returnPersonData::collection(Person::all());
.What would be the cleanest way to construct this nested structure using the
::collection
method?Beta Was this translation helpful? Give feedback.
All reactions