【问题标题】:artisan output one by one工匠一一输出
【发布时间】:2018-04-10 01:00:17
【问题描述】:

如果我在控制台中运行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());

我正在寻找一种方法来为每个表一个一个地显示 Artisan::output()(与在控制台中运行命令相同的行为)。

【问题讨论】:

    标签: php laravel laravel-5 console laravel-artisan


    【解决方案1】:

    您的代码按其方式运行的原因是,在命令完成后您会显示该命令的输出:

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

    为了在运行迁移的过程中显示执行的 migrate:fresh 命令的输出,您需要将其输出到父命令的输出而不是它自己的输出,这是稍后的Artisan::output() 阅读。

    下面的代码可以解决问题:

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

    注意传递给call() 方法的第三个参数。

    【讨论】:

      猜你喜欢
      • 2018-06-24
      • 2021-01-29
      • 1970-01-01
      • 2015-05-24
      • 2021-09-15
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      相关资源
      最近更新 更多