Last active
February 14, 2022 18:27
-
-
Save a-h-abid/9359d07f874bb00b033ba4a3ad801a10 to your computer and use it in GitHub Desktop.
To get scheduled tasks in system. Tested in Laravel 6+.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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