gpt4 book ai didi

laravel - 播种或迁移表时,如何向控制台提供输出?

转载 作者:行者123 更新时间:2023-12-01 07:17:44 25 4
gpt4 key购买 nike

我在10月有一个插件,我正在创建必要的表格,并根据文档将其播种。

我希望在执行此操作时提供控制台输出,以便我可以调试正在设置的过程并捕获任何可能的情况。

运行php artisan october:up时如何将信息输出到控制台?

use Db;
use Seeder;

class SeedGeoStateTable extends Seeder
{
public function run()
{
foreach(array_merge(glob(__DIR__.'/seed/geo_state/*.txt'), glob(__DIR__.'/seed/geo_state/*.json')) as $file) {
$this->insert($file);
gc_collect_cycles();
}
}

public function insert($file) {
// output to console which file i'm seeding here
$json = json_decode(file_get_contents($file),true);
foreach($json as $entry) {
Db::table("geo_state")->insert($entry);
}
}
}

最佳答案

在您的播种机中,您可以使用command属性,并可以使用以下方法:

$this->command->info($message)
$this->command->line($message)
$this->command->comment($message)
$this->command->question($message)
$this->command->error($message)
$this->command->warn($message)
$this->command->alert($message)

要查看所有可用方法,请检查 Illuminate\Console\Command

示例
public function run()
{
$this->command->comment('Seeding GeoState...');
foreach(array_merge(glob(__DIR__.'/seed/geo_state/*.txt'), glob(__DIR__.'/seed/geo_state/*.json')) as $file) {
$this->insert($file);
gc_collect_cycles();
}
}

关于laravel - 播种或迁移表时,如何向控制台提供输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45864171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com