Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

swiftroot's avatar

Advice on dynamic fields

Looking to create dynamic field associations within resources (Fields not hard-coded). As an example, I have a LineItem which has some basic fields like price and quantity. Some LineItems will have a slight variation, say an extra field for the shipping type or tax class.

What I'd like to do (end goal) is to add dynamic fields to this LineItem resource. When creating this resource, depending on which 'type' you selected, these extra fields would show in the Nova create form.

Some things I've considered:

  1. Create 5 separate models. This seems non-practical and ugly. Perhaps some kind of inheritance?
  2. Create a MetaField resource with a relationship to LineItem. The issue is validation. If an administrator is adding a LineItem manually, depending on the type they select, I would love these extra fields to be available as defaults. Perhaps I would need another table, MetaFieldOptions which would define constraints.
  3. I've considered making my own custom field of fields. A collection (rows) of fields that could be added in-line.

My questions:

  1. Is there a better way of doing option 1, with some kind of inheritance (Including table creation).
  2. Or, can I somehow customize the resource creation forms to facilitate this dynamic presentation of data (Without hacking Nova).
  3. Would option 3 be ultimately the easiest?
0 likes
1 reply

Please or to participate in this conversation.