我的Cron工作在laravel中无法正常工作

时间:2019-04-24 07:19:35

标签: laravel laravel-5 cron

我正在做laravel crone工作,它只工作一次,我的代码只执行一次,我是初学者

  protected function schedule(Schedule $schedule)
  {
      $schedule->command('list:users')->everyMinute();
  }
class ListUsers extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'list:users';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'corn job command';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $totalUsers = \DB::table('users')->whereMonth('created_at','04')->count();
        Mail::to('qasim@gmail.com')->send(new SendMailable($totalUsers));
    }

我也尝试使用此代码

 protected function schedule(Schedule $schedule)
 {
     $schedule->call(function () {
            echo "pakistan\n";
            $totalUsers = \DB::table('users')->whereMonth('created_at','04')->count();
            Mail::to('qasim@gmail.com')->send(new SendMailable($totalUsers));
            echo "pakistan";
        })->everyMinute();
    }

我希望用户每分钟收到一次电子邮件 我收到邮件一次但不是每分钟

0 个答案:

没有答案