Model with different layout based on category

Hello all, I would like your help on how to achieve this logically taking in account good coding principles, indexing and performance issues. Imagine the following: - A model of "Books" - Books can have different "Categories" - When creating a Book: -- If category is Fiction shows fields A, B and C -- If category is Non-Fiction shows fields D, E, F My questions: - How should I store that data? -- Should I have all those fields in the database and leave empty depending on category -- Or should i just have a "meta" column and store it as JSON? - How would I show each field set based on category selected? Thank you. I'm new to filament and before getting hands on I'm trying to write all the logic behind this. Thanks!
Solution:
Personnally, I think I would choose to have all fields as columns on the table and simply store NULL when a field is not applicable to the current item. Storing all fields inside of one JSON column is possible, but keep in mind that it could limit what you can do with the data at the SQL level (searching, filtering, etc.)
Jump to solution
3 Replies
Solution
Patrick Boivin
Patrick Boivin16mo ago
Personnally, I think I would choose to have all fields as columns on the table and simply store NULL when a field is not applicable to the current item. Storing all fields inside of one JSON column is possible, but keep in mind that it could limit what you can do with the data at the SQL level (searching, filtering, etc.)
Patrick Boivin
Patrick Boivin16mo ago
You can use ->hidden(...) or ->visible(...) on each field to determine if it should be shown in the current context: https://filamentphp.com/docs/3.x/forms/advanced#conditionally-hiding-a-field
Diogo Pinto
Diogo PintoOP16mo ago
Thank you so much for your input @Patrick Boivin.
Want results from more Discord servers?
Add your server