Home > OS >  How to run task scheduler locally on Laravel 7?
How to run task scheduler locally on Laravel 7?

Time:04-05

I want to learn how to use task scheduler in Laravel 7

According to the documentation, I created a task that should send out a test message to the mail on Mondays at 16:00. Judging by the documentation for local development, there is no need to add a cron entry. I just run the command php artisan schedule:work get this error Command "schedule:work" is not defined. Where am I making a mistake?

 protected function schedule(Schedule $schedule)
  {
   $schedule->call(function () {
       $test = 'test';
       $email = Emails::where('id', 1)->first();

       Mail::to($email)->send(new TestMail($test));
    })->mondays()->at('16:00');
}

After I tried to add the line * * * * * cd /public_html/my_project && php artisan schedule:run >> /dev/null 2>&1 but got the following message bash: README_CI.md: command not found

CodePudding user response:

you can try this

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

CodePudding user response:

you have cd /your/path. better do php /public_html/my_project/artisan schedule:run as cd'ing in cronjob does not work unless you have a bash script instead of inline.

as for schedule:work, that commmand should exist, does artisan (without arguments produce a list of options including schedule:work?

  • Related