I’m working on a Laravel project where each service has a dynamic form layout configured through a backend admin panel. The project has the potential to grow to over 900 services, with each service containing a minimum of 9 forms, summing up to more than 8100 forms.
The challenge is that we don’t always know what the input fields will be in advance. Although I’ve made the system capable of saving dynamic inputs, adding a new field or section to the form configuration currently requires creating new columns in the database. For nested layouts, I pass nested input names, for example, cases[project_experiences][name]. When saving, I manually create each relationship (e.g., cases has many project_experiences, and project_experiences belong to specific mapping tables with a column type project_experience).
The project is continually maintained by me, so old code mixing with new code has made it risky to change the current process. Therefore, I use multiple tables. Currently, I have a mapper that takes nest_id (e.g., project_experience belongs to the companyStaff table, so I map it and create new columns if they do not exist). I repeat this process, but we have only completed 3 services so far.
I plan to implement DTOs for each service to transform backend form configurations into a schema. Then, I can use that schema for validation, migration, and saving data. For DTOs, I use spatie/laravel-data and for schemas, I use opis/json-schema.
I successfully created DTOs that convert to schema, but I haven’t made it able to migrate and sync with the table or dynamic saving to replace the current process.
I expect you to give me some advice?
Is this a good choice to introduce DTOs and schemas in this scenario?
Will this approach be sustainable in the long run, or do I need to consider alternative methods for saving and managing dynamic forms?
By the way, I’m still a junior developer, so don’t mind me please said all you want and Thank you for your attention!
1