[Answered] Add a field without destroying data
emergingdzns - 1 month ago
I've got a module mostly complete and the client has asked for another column of data (so a new field in the form) to be added, but we already have a lot of data in the tables for the module. This particular model is ok to wipe out but so far all I've been able to do is a reinstall of the module, causing all of the data in the tables to get wiped out. I have to keep exporting, reinstalling, and then reimporting.
Is there a way to add a single field to a model as a migration and not destroy all the data in the whole module?
ryanthompson - 1 month ago
You can add a migration to the model with laravel command:
php artisan make:migration --addon=you_addon
Then use the
streams() methods to create stuff like you normally would:
$stream = $this->streams()->findBySlugAndNamespace('foo', 'bar'); $field = $this->fields()->create($attributes); $this->assignments()->create(compact('stream', 'field');