2017-10-28 198 views
1

如果我在控制台中运行php artisan migrate:fresh --seed --force一切都按预期工作。 输出逐个显示。工匠输出一个一个

Dropped all tables successfully. 

Migration table created successfully. 

Migrating: 2014_10_12_000000_create_users_table 

Migrated: 2014_10_12_000000_create_users_table 

Seeding: UsersTableSeeder 

etc. 

如果我从Laravel运行artisan命令,除了输出外,一切正常。它在所有操作的最后显示一次。

$this->info('Migrating and seeding the database...'); 
Artisan::call('migrate:fresh', [ 
    '--seed' => true, 
    '--force' => true, 
]); 
$this->line(Artisan::output()); 

我寻找一种方法来显示工匠::输出()逐个对每个表(相同的行为等运行在控制台中的命令)。

回答

1

为什么你的代码工作它的方式是,你显示该命令的输出一旦它被完成,其原因是:

$this->line(Artisan::output()); 

为了显示执行迁移的输出:新鲜命令随着迁移过程的进行,您需要将其输出到父命令的输出中,而不是自己的输出中,稍后由Artisan :: output()读取。

下面的代码将这样的伎俩:

$this->info('Migrating and seeding the database...'); 
Artisan::call('migrate:fresh', [ 
    '--seed' => true, 
    '--force' => true, 
], $this->output); 

通知传递给call()方法的第三个参数。