为什么时间表不能自动运行

问题描述 投票:0回答:1

我尝试在开始考试前 1 小时向课程用户发送通知,因此,我发出了发送通知的命令,问题是当我运行 php artisan Schedule:work in cmd 时,通知将保存在数据库和时间表中有效,但是当我期望它自动运行并注意到保存在数据库中时。 预先感谢

内核.php

     protected function schedule(Schedule $schedule)
    {
     
       $schedule->command('users:notify')->everyMinute();
    }

通知用户.php

class NotifyUsers extends Command
{
         protected $signature = 'users:notify';
         protected $description = 'notify to users';

public function handle(){
         $quizzes = Quiz::whereDate('start_date', now()->addHour())->get();
         $students = [];
         $titles = [];
              foreach($quizzes as $quiz){
                 $students = $quiz->course->users;
                     $title = $quiz->title;
                     array_push($titles, $title );
                  }
                  foreach($titles as $title){
                     foreach($students as $student){
                          Notification::send($student, new timeToExam($title));
                  }
             }
        
    }

timeToExam.php // 通知

class timeToExam extends Notification
                         {
        use Queueable;

         public $title;

    
public function __construct($title)
{
    $this->title = $title;
}

public function via($notifiable)
{
   return ['database'];
}

  
public function toArray($notifiable)
{
    return [
          'title' => $this->title,
        ];
}
php laravel scheduled-tasks
1个回答
0
投票

你只需要在你的 Windows 机器上设置一个 cron 作业。 此链接可能会帮助您找到解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.