2017-10-28 204 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()方法的第三個參數。