I've searched in the docs and fiddled with the Laravel code but found nothing about it. I'm using Laravel 5.1.
I want to know if I can extend the Schema::create function or do something in terms of reverse migration. I want to recover the fields and types set during migration and output them to a json file for each migration file (there are many). This file will be used in angular formly. This way I can generate everything during the migration command.
I believe repeating the code for each migration is not the best approach. Any ideas?
class CreatePlanTypesTable extends Migration
{
public function up()
{
Schema::create('plan_types', function (Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('slug');
$table->dateTime('created_at');
$table->dateTime('updated_at');
// ---- dont want to repeat for each migration file -----
$json = [];
$columns = $table->getColumns();
foreach($columns as $column)
{
$json[] = [
'key' => $column['name'],
'type' => $column['type'],
'templateOptions' => [
'label' => '',
'placeholder' => ''
]
];
}
file_put_contents('tablefile.json', json_encode($json));
// -------------------
});
}
...