Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adsofts's avatar

Reverse migrations file

Hello. I have a problem for which I am looking for a solution. I keep looking for a method on my own but I also post here in case someone has an interesting idea. I'm trying to be able to "read" the migration files of a Laravel project. My goal is to be able to create a JSON file containing all the definitions of tables and fields (name, type, keys, ect.) created with the migrations to then be able to regenerate the migration files myself from my JSON. I can use Reflection to read the definitions of the classes contained in the migrations but at the moment I have no idea how to interpret the contents of the "up" methods so that I can build an array containing the list of tables and fields. I know it's a bit special as a request. In fact I don't know if it's really possible. But it's an interesting little challenge. So if anyone has any idea how to do it, that would be great :) Thank you

0 likes
5 replies
Sinnbeck's avatar

Can you perhaps explain why you need to do this? Perhaps we can suggest a better solution then.

adsofts's avatar

Hello. Thank you for your answer. My final goal is to create some sort of "phpmyadmin" using only migrations from a Laravel project. No problem to generate the migration files for the tables created or modified from my tool. But I would also like that my tool can be used on an existing project and for that I need to be able to "understand" the existing migration files.

adsofts's avatar

@Sinnbeck This technique does not suit me because it simply gives a "picture" of the database. I'm looking to create a visual migration manipulation tool that will also keep the history of additions / modifications. Also, I don't want projects using my Package to be dependent on this package. This is why I want to be able to read and generate migration files so that the functionalities remain accessible via the standard Artisan manipulations (migrate, rollback, ect.)

Funfare's avatar

Maybe you can change the bindings for Blueprint class and facade for Schema and then track what methods are called.

Please or to participate in this conversation.