4

I found many results how to create migration from a model, but is there any way to create a model from migrations?

Basically I want to give a table name, and if there is multiple migration files (one to create and others to update the previous states) the model could be updated.

Is there any solution for this?

4
  • What do you want to be updated in the model? Commented Jul 20, 2019 at 9:17
  • I create a migration what define name and size fileds. Later I create an other migration what is extend this table with a color filed. Now this is 2 files in migrations. If I generate model only from the first one it will be not good. Commented Jul 20, 2019 at 9:38
  • ...but you would only want one Model as there is only one table. So, what would you want to change in that model class based on the 2nd migration? Commented Jul 20, 2019 at 9:41
  • Okay, in my head was the migration files, not the tables. Now I understand you. Commented Jul 20, 2019 at 9:43

1 Answer 1

4

I'm not sure that there's a good way to create a model directly from migrations, as it depends on what database you use as to the exact structure of your tables.

There seems to be a package which support generating the models from your database, however: https://github.com/laracademy/generators

Sign up to request clarification or add additional context in comments.

3 Comments

I using many migrations with many fields, and if the generated models aren't perfect is better than write each by hand.
The package above should work correctly, provided your database is migrated when you run the generation command.
Warning: the package above laraacademy/generators did NOT work well for me. It created the wrong fields. fyi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.