mercredi 2 septembre 2015

Creating new tables for each model instance in Laravel

I'm using Laravel 5.1 to build an application for creating forms.

Each form will be an instance of the Form model. Each form will potentially have a different range of fields. The possible fields are defined in a Fields table (i.e: first_name, surname, date_of_birth, postcode, etc). There is a has-many relationship between the Form and the Field models.

To collect the form data, I was considering creating a new table for each Form instance.

For example, the user creates a form with the fields first_name, surname, date_of_birth and postcode. When the form is added, a table will be created using Schema::create('form_' . $form->id, function($table) {[... fields ...}).

When a user submits the form, the data will be validated using the Form instance as the model and then inserted into the defined table.

I suspect this is a bad or unorthodox idea (mainly because creating tables on the fly feels risky) but would appreciate a second opinion. Is there a better way of approaching this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Q83nxD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire