Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

  1. Create new model via php artisan make:model -a (Model name, singular form). This creates the model, migration file, seeder file, model factory, and model controller.

  2. Write the migration file to match proposed schema, being sure to set unique constraints and foreign keys as appropriate.

  3. Write any mandatory seeder data that should be populated in the Database on install.

  4. Write the model factory, making use of Faker to populate dummy data.

  5. Remove the equivalent table from the seed.sql scripts. Usually there are several places where it is referenced, for example creating the table, then creating the sequence for the primary key, then possibly more ALTER TABLE statements further down.

  6. In the legacy DB classes, modify the base file and base peer file to reference the new schema. The former defines the fields in the table, the latter also references their data types.

  7. In the legacy model, first remove any unused methods. Then for each remaining method, determine if it’s something that’s best replaced with a simple getter or setter from the new model. In Laravel, magic methods exist for single fields in a table. E.g., if there’s an email column for the User, you can make use of a $user->getEmail() method without having to actually define it in the model.

  • No labels