skip to Main Content

I have a file Commands/DateUpdate.php

protected $signature = 'date:update';
public function handle()
{
    $listSchedule = Schedule::where('dateSchedule', '=', strtotime('now'))->get()->toArray();
    $dateSchedule = [];
    foreach ($listSchedule as $value) {
        $dateSchedule[] = $value['dateSchedule'];
    } 
    var_dump($dateSchedule);
    // result
    // array(3) {
    //     [0]=>
    //     string(16) "2023-01-05 09:16"
    //     [1]=>
    //     string(16) "2023-01-05 11:45"
    //     [2]=>
    //     string(16) "2023-01-05 15:25"
    //   }

}

In Kernel.php
$schedule->command('date:update');
I want to schedule it according to the time in the $dateSchedule variable.
Example:

foreach ($dateSchedule as $item) {
    ->at($item);
};

How can this be done?

2

Answers


  1. You can try by compare current time with dateSchedule

    foreach ($listSchedule as $value) {
      if (now()->diffInMinutes($value['dateSchedule']) === 0) {
        $this->call('another:command');
      }
    }
    
    Login or Signup to reply.
  2. You can use

    foreach ($dateSchedule as $item) {
        $schedule->call(function () {
            $this->call('date:update');
        })->at($item);
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search