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
update all the property records accordinglyJust to make sure I understand - each boolean property is stored in its own record? What does this relationship look like on the parent model?
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.
Do you think a Repeater would be a good fit for this?
https://filamentphp.com/docs/3.x/forms/fields/repeater
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
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?
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!)
Personally, I would use an Enum for vehicle types then load different form fields / tabs based on the vehicle type.
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.
makes sense. would a KeyValue field work?
Thats the approach I'm trying - properties[property_id] = value
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
ah - possibly - I'll take a look
thanks for the heads up