Advice required: Form editing / saving Parent and many children

Hi all. I'm after some advice. I have a product table and I have a product properties table - 1 product may have up to 65 properties (at present) and the majority of the properties are boolean. I want to present this information in a single form - top section is the product information and then 'n' tabs each with a number of the properties on the tab that the user may switch on or off. Once happy then I want the user to click the save button to save the parent record and then update all the property records accordingly. In my past life I would have an array <input name='product[property][index of property]' value=false> that is then sent over to receipient of the request. I hope that makes sense How would I achive this in Filament? Thanks in advance Jon
12 Replies
Patrick Boivin
Patrick Boivin15mo ago
update all the property records accordingly
Just to make sure I understand - each boolean property is stored in its own record? What does this relationship look like on the parent model?
JonVonWeston
JonVonWestonOP15mo ago
Hi Patrick - 1 to many - so a product has a category - ie a vehicle can be a hatchback and a vehicle can have many properties - colour, engine size, cruise control etc.
JonVonWeston
JonVonWestonOP15mo ago
Don't think so - although the majority of child properties are boolean - such as power steering , abs etc. some are inputs - registration number, or selects - fuel type etc. I also want to spread the properties across multiple tabs - vehicle, interior features, exterior features etc. from my understanding a repeater is exactly that - repeating blocks of controls
Patrick Boivin
Patrick Boivin15mo ago
Makes sense. Maybe a Builder field then, if the repeatable items can be of various types (as opposed to all booleans). But you're right, if you want to organize the properties in Tabs, neither will work. Are the properties fixed for a given item, or can a user decide to add extra properties?
JonVonWeston
JonVonWestonOP15mo ago
The properties are dynamic on a product - so for a vehicle they could have a set of properties vin / engine size etc. but for trailer might be a different set of properties - load capacity / powered brakes etc. and they may want to add a new property later on - colour for example that can be relevant on both cars, trailers and horseboxes say its a complex problem! (but a fun one!)
awcodes
awcodes15mo ago
Personally, I would use an Enum for vehicle types then load different form fields / tabs based on the vehicle type.
JonVonWeston
JonVonWestonOP15mo ago
I'm using category to define the type - reason for this is to allow for hierarchial categories - Trailer -> Flat Bed -> 2 wheel, and the user is able to assign properties relevant to each of those cateogies and when I create the product I traverse that hierachy and create a list of properties that apply to a 2 wheeled flat bed trailer.
awcodes
awcodes15mo ago
makes sense. would a KeyValue field work?
JonVonWeston
JonVonWestonOP15mo ago
Thats the approach I'm trying - properties[property_id] = value
awcodes
awcodes15mo ago
I mean, there's an actual KeyValue field for Filament. Could that work for your needs. https://filamentphp.com/docs/3.x/forms/fields/key-value
JonVonWeston
JonVonWestonOP15mo ago
ah - possibly - I'll take a look thanks for the heads up
Want results from more Discord servers?
Add your server