-
Hey, https://nova.laravel.com/docs/4.0/resources/fields.html Let's say for example, I wanted to display a user's street address in the listing here (see above). The street column is available on the addresses relationship. Taking this a step further, is there a way to do more advanced stuff, like take the above example and have it display the user's primary address from the addresses relationship? The primary address is also a column on the relationship. Lastly, is there a way to grab data (that we know of) and display it in a column? We currently use the Code field to display the whole thing in the detailed view, though it would be great if we could display some the stuff in the listing also. The only thing that springs to mind is having multiple accessors on the model. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I can't remember if I've tested it on relationships, but, I'm showing 'nested properties' using dot-notation. For your use-case, maybe dot-notation works on referencing relationships as well? Text::make(__('Primary Street Address'), attribute: 'addresses.primary.street') Other than that, what comes to mind directly is computed fields. Text::make(__('Primary Street Address'), function (User $user): string {
// Replace with what makes sense. I'm assuming your 'addresses' aren't keyed like this,
// but for simplicity in this example.
return $user->addresses->get('primary')?->street;
}) |
Beta Was this translation helpful? Give feedback.
-
Oh wow. Magic! The dot notation works great for both relationships and JSON. Thanks @juse-less! Example 1
Example 2
Example 3
|
Beta Was this translation helpful? Give feedback.
I can't remember if I've tested it on relationships, but, I'm showing 'nested properties' using dot-notation.
Basically, say, my user has a JSON column of values, or I'm using casts to build a property that is an array, then I can refer to one of the nested properties using dot-notation.
For your use-case, maybe dot-notation works on referencing relationships as well?
Other than that, what comes to mind directly is computed fields.