whitecube / nova-flexible-content

Flexible Content & Repeater Fields for Laravel Nova
MIT License
787 stars 234 forks source link

Modifying attributes output #280

Closed jakecausier closed 3 years ago

jakecausier commented 3 years ago

Hi there, this might be a little difficult to explain what I'm trying to do, but I hope it makes sense.

I'm currently using Laravel Jetstream with the Interia stack which utilises Vue to render page content. I was working to implement this package to return layout instances and create Vue components dynamically, which is working fine, but I need to return Images attached using the ebess/advanced-nova-media-library fields, which do not show in the attributes output (as they need to be accessed via. the getMedia function on the layout instance.

Is there a way to intercept what the layout outputs in the attributes field? I figure I can merge in some extra fields for my attached image to return the URLs I need for rendering. I had a look into casts and resolvers but it confused me.

toonvandenbos commented 3 years ago

Hi @jakecausier,

Indeed, a custom resolver is what you'll need. In this case you could basically start with the default resolver included in this package and tweak it so it includes what you need in certain layouts.

Another option would maybe be to define accessor methods on your flexible layouts (you'll need to define them using custom layout classes) such as getMediaAttribute() which would retrieve the data you're looking for just by accessing $layout->media.