We are facing an issue with Laravel scheduled tasks using the call
method in Kernel.php
not executing as expected in development mode on Windows. When running php artisan schedule:work
, it only displays "No scheduled commands are ready to run," even though a simple task has been added.
Here’s the minimal example we’re using in Kernel.php
:
protected function schedule(Schedule $schedule) { $schedule->call(function () {Log::info("Hello world"); })->everyMinute(); }
We expected to see "Hello world" appear in the log file (storage/logs/laravel.log
), but it doesn’t.
Steps we’ve already tried:
-
Verifying the syntax of the
Kernel.php
file. -
Running the appropriate Artisan commands:
php artisan schedule:run
andphp artisan schedule:work
. -
Checking the permissions on the log file.
Despite these attempts, the scheduled task is not working. Does anyone have suggestions to resolve this?
2
Answers
Thank you @AmirHossein AshariNik for your detailed answer showing how to use
bootstrap/app.php
. However, I've actually already solved my issue by moving the scheduling code toroutes/console.php
, as this appears to be the new recommended location for schedule definitions in Laravel 11.In Laravel 11, you can use
bootstrap/app.php
file, as well. Use thewithSchedule
function. Here’s how you can modify this file to include a scheduled task:Test the scheduler locally using the Artisan command: