/**
* Make the json migration
*
* @return void
*/
protected function makeJsonMigration()
{
// Set start time of file generation
$this->startTime = time();
// Get json array from file
$jsonArray = $this->makeMigrationJson->jsonFileToArray($this->filePath);
// Parse only option
$only = [];
if (!empty($this->option('only'))) {
$only = explode(',', $this->option('only'));
$only = array_map('trim', $only);
}
// Parse json and get schema
$schema = $this->makeMigrationJson->parseSchema($jsonArray, $only);
// For every migration in the schema
foreach ($schema as $migrationName => $fieldSchema) {
// Check if this migration is a pivot table
if (substr($migrationName, -6) === '_pivot') {
// Get tables
$tables = explode(' ', $fieldSchema, 3);
// Invoke the extended generator command for pivot tables
$this->call('make:migration:pivot', ['tableOne' => $tables[0], 'tableTwo' => $tables[1]]);
// Go to next migration
continue 1;
}
// Invoke the extended generator command
$this->call('make:migration:schema', ['name' => $migrationName, '--schema' => $fieldSchema]);
// wait 1 second in-between schemas to run the insequence later with "php artisan migrate"
sleep(1);
}
// $this->info(var_export($schema, true));
}