2016-12-19 3 views
0

私はScheduleでlaravelでcronを実行していますが、cronの実行のパラメータの日付は固定されていません。私は後でcron実行のためのパラメータとして使用するデータを格納するテーブルを持っています。問題は、私がどのようにしてレコードに書き込み時のコントローラから、私がcronのためにカーネルに持っているクエリにそのレコードを送ることができるかわからないことです。ここでLaravelのカーネルスケジュール機能にパラメータを送信する方法は?

はカーネル内にある関数である:

protected function schedule(Schedule $schedule) 
{ 
$schedule->command('inspire') 
     ->hourly(); 

$schedule->call(function() { 

    $programacion = 
    DB::table('plantrabajoalerta') 
    ->select(DB::raw('tareaFechaInicioPlanTrabajoAlerta, tareaHoraPlanTrabajoAlerta, tareaIntervaloPlanTrabajoAlerta, tareaDiaLaboralPlanTrabajoAlerta, tareaDiasPlanTrabajoAlerta, tareaMesesPlanTrabajoAlerta')) 
    ->where('idPlanTrabajoAlerta',"=", $id) 
    ->get(); 

    $schedule->command('log:plantrabajo')->cron('minuto hora dia * * *'); 

}); 

} 

答えて

0

あなたのcronジョブに呼び出しを介して何かを送信することはできません。しかし、あなたのlog:plantrabajoコンソールコマンド内でそのコードを実行することはできますか?

だから、あなただけの

protected function schedule(Schedule $schedule) 
{ 
    $schedule->command('inspire')->hourly(); 

    $schedule->command('log:plantrabajo')->hourly(); 
} 

そして、あなたのコンソールコマンドは、そのクエリを実行するのに持っている:

<?php 

namespace App\Console\Commands; 

use Illuminate\Console\Command; 

class PlanTrabajoCommand extends Command 
{ 
    /** 
    * The name and signature of the console command. 
    * 
    * @var string 
    */ 
    protected $signature = 'log:plantrabajo'; 

    /** 
    * The console command description. 
    * 
    * @var string 
    */ 
    protected $description = 'Do whatever'; 

    /** 
    * Execute the console command. 
    * 
    * @return mixed 
    */ 
    public function handle() 
    { 
     $programacion = 
      DB::table('plantrabajoalerta') 
       ->select(DB::raw('tareaFechaInicioPlanTrabajoAlerta, tareaHoraPlanTrabajoAlerta, tareaIntervaloPlanTrabajoAlerta, tareaDiaLaboralPlanTrabajoAlerta, tareaDiasPlanTrabajoAlerta, tareaMesesPlanTrabajoAlerta')) 
       ->where('idPlanTrabajoAlerta',"=", $id) 
       ->get(); 

     foreach($programacion as $evento) { 
      ... 
     } 
    } 
} 
関連する問題