Skip to content

Instantly share code, notes, and snippets.

@a-h-abid
Last active February 14, 2022 18:27
Show Gist options
  • Save a-h-abid/9359d07f874bb00b033ba4a3ad801a10 to your computer and use it in GitHub Desktop.
Save a-h-abid/9359d07f874bb00b033ba4a3ad801a10 to your computer and use it in GitHub Desktop.
To get scheduled tasks in system. Tested in Laravel 6+.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\Scheduling\Schedule;
class ScheduleListCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'schedule:list';
/**
* The console command description.
*
* @var string
*/
protected $description = 'List all scheduled tasks';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$schedule = app(Schedule::class);
$events = collect($schedule->events());
$allEvents = [];
foreach ($events as $event) {
$allEvents[] = [
'cron' => $event->expression,
'command' => $event->command,
];
}
$this->table(
['Cron', 'Command'],
$allEvents
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment