2017-08-24 1 views
0

私は10月にプラグインを持っています。私は必要なテーブルを作成し、ドキュメントごとにそれをシードします。テーブルのシードまたはマイグレーション時にコンソールに出力を提供するにはどうすればよいですか?

これを実行する際にコンソール出力を提供したいので、私が設定しているプロセスをデバッグすることができます。

php artisan october:upの実行時に情報をコンソールに出力するにはどうすればよいですか? symfonyのクラスConsoleOutput

$output = new \Symfony\Component\Console\Output\ConsoleOutput(2); 

$output->writeln('hello'); 

コンソールにこの意志の出力情報を使用することにより

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); 
     } 
    } 
} 
+0

あなたは 'echo'を試してみましたか? – Wreigh

答えて

0

。あなたのシーダで

例の場合

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 
     $output = new \Symfony\Component\Console\Output\ConsoleOutput(2); 
     $output->writeln("Seeding table with file $file"); 
     $json = json_decode(file_get_contents($file),true); 
     foreach($json as $entry) { 
      Db::table("geo_state")->insert($entry); 
     } 
    } 
} 
0

、使用可能な次のような方法で、利用可能command性質を持っている:すべての利用可能な方法はIlluminate\Console\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) 

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(); 
    } 
} 
+0

はい、それが私が試した最初のものですが、10月の '[Symfony \ Component \ Debug \ Exception \ FatalThrowableError]でnullになります。 メンバー関数info()on nullを呼び出しています。問題。 – Tschallacka

+0

彼らはLaravelに基づいているため、10月は完全にカスタマイズ可能だと主張していますが、Seedersのようなカスタムコンポーネントに関するドキュメントが不足しているようです:/ – Desh901

+0

確かにオブジェクトはそこにあります。人口が多い。または、おそらく私はシードャーを間違って呼んでいるだけですが、ちょっと、私は10月のドキュメントが基本的に "コードを見て、それを理解してください、laravelsドキュメント、幸運を見てよ!だから私はそれがどれくらいまで来たのかと幸せだ。それは非常にパワフルで、ララベリにはうってつけです。 – Tschallacka

関連する問題