LARAVEL: Get an array of scheduled tasks for output in admin dashboard

As your not running through the console you need to invoke the schedule method on the Kernel in your controller... (don't forget to make the schedule method public instead of protected).

public function index(\Illuminate\Contracts\Console\Kernel $kernel, \Illuminate\Console\Scheduling\Schedule $schedule)
{
    $kernel->schedule($schedule);
    dd($schedule->events());
}

There's actually no support out of the box for this, unfortunately. What you'll have to do is extend the artisan schedule command and add a list feature. Thankfully there's a simple class you can run:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Console\Scheduling\Schedule;

class ScheduleList extends Command
{
    protected $signature = 'schedule:list';
    protected $description = 'List when scheduled commands are executed.';

    /**
     * @var Schedule
     */
    protected $schedule;

    /**
     * ScheduleList constructor.
     *
     * @param Schedule $schedule
     */
    public function __construct(Schedule $schedule)
    {
        parent::__construct();

        $this->schedule = $schedule;
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $events = array_map(function ($event) {
            return [
                'cron' => $event->expression,
                'command' => static::fixupCommand($event->command),
            ];
        }, $this->schedule->events());

        $this->table(
            ['Cron', 'Command'],
            $events
        );
    }

    /**
     * If it's an artisan command, strip off the PHP
     *
     * @param $command
     * @return string
     */
    protected static function fixupCommand($command)
    {
        $parts = explode(' ', $command);
        if (count($parts) > 2 && $parts[1] === "'artisan'") {
            array_shift($parts);
        }

        return implode(' ', $parts);
    }
}

This will provide you with a php artisan schedule:list. Now that's not exactly what you need, but then you can easily get this list from within your Laravel stack by executing:

Artisan::call('schedule:list');

And that will provide you with a list of the schedule commands.

Of course, don't forget to inject the Facade: use Illuminate\Support\Facades\Artisan;


In case anyone is like me and is trying to do this in 2021. Based on old answers and a bit of playing around.

In Laravel Framework 8.22.1 I got to work by making app/Console/Kernel->schedule method public and then in a Controller:

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Events\Dispatcher;

    private function getScheduledJobs()
    {
        new \App\Console\Kernel(app(), new Dispatcher());
        $schedule = app(Schedule::class);
        $scheduledCommands = collect($schedule->events());

        return $scheduledCommands;
    }

Hope this saves time for future googlers like myself.


I was having the task to stop/enable and edit the frequency of the scheduled tasks from the admin dashboard. So I foreach them in Kernel.php and capture the output in function.

$enabled_commands = ConsoleCommand::where('is_enabled', 1)
        ->get();

    foreach ($enabled_commands as $command)
    {
        $schedule->command($command->command_name)
            ->{$command->frequency}($command->time)
            ->after(function () use ($command) {
                $this->log($command->command_name);
            });
    }

Hope this help you.