PHP code example of kapersoft / cron-job-api-for-laravel

1. Go to this page and download the library: Download kapersoft/cron-job-api-for-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kapersoft / cron-job-api-for-laravel example snippets


use Kapersoft\CronJobApi\Client;

final readonly class JobsController
{
    public function __construct(private Client $client) {}

    public function index() {
        $list = $client->list();
        // ...
    }
}

use Kapersoft\CronJobApiForLaravel\Facades\CronJobApi;

$jobs = CronJobApi::list();

use Kapersoft\CronJobApi\Job;

$jobList = $client->list();
foreach ($jobList->jobs as $job) {
    /** @var Job $job */
    echo $job->jobId.' '.$job->title.PHP_EOL;
}

$detailed = $client->get(123); // returns DetailedJob
echo $detailed->title;

use Kapersoft\CronJobApi\{Job, Schedule, RequestMethodEnum};

$newJobId = $client->create(new Job(
    enabled: true,
    title: 'Ping production',
    url: 'https://example.com/health',
    requestTimeout: 30,
    redirectSuccess: true,
    schedule: new Schedule(
        timezone: 'UTC',
        expiresAt: 0,        // 0 = never expires
        hours: [-1],         // every hour
        mdays: [-1],         // every day of month
        minutes: [0, 30],    // on minute 0 and 30
        months: [-1],        // every month
        wdays: [-1],         // every day of week
    ),
    requestMethod: RequestMethodEnum::GET,
));

$client->update($newJobId, new Job(title: 'Ping prod (renamed)'));

$client->delete($newJobId);

$history = $client->history(123);
$firstRun = $history->history[0];
$details = $client->historyItem(123, $firstRun->identifier);
bash
php artisan vendor:publish --provider="Kapersoft\\CronJobApiForLaravel\\CronJobApiServiceProvider"