PHP code example of cardinal / laravel

1. Go to this page and download the library: Download cardinal/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/ */

    

cardinal / laravel example snippets


// config/cardinal.php
return [
    'enabled'               => env('CARDINAL_ENABLED', true),
    'sample_rate'           => env('CARDINAL_SAMPLE_RATE', 1.0),
    'slow_threshold_ms'     => 500,
    'n_plus_one_threshold'  => 10,
    'ignore' => [
        'tables' => ['telescope_*', 'pulse_*', 'jobs', 'sessions', 'cache'],
        'paths'  => ['horizon*', 'telescope*'],
    ],
    'storage' => [
        'retention_days' => 14,
    ],
    'explain' => [
        'enabled'        => true,
        'on_demand_only' => true,
    ],
    'ai' => [
        'provider' => env('CARDINAL_AI', null),  // 'anthropic' | 'openai' | null
        'api_key'  => env('CARDINAL_AI_KEY'),
        'model'    => env('CARDINAL_AI_MODEL', 'claude-sonnet-4-6'),
    ],
];
bash
composer migrate
bash
php artisan vendor:publish --provider="Cardinal\CardinalServiceProvider" --tag="config"
bash
php artisan cardinal:report
php artisan cardinal:report --type=slow
php artisan cardinal:report --type=n_plus_one
php artisan cardinal:report --type=missing_index
bash
php artisan cardinal:analyze ab12cd34ef56
bash
php artisan cardinal:fix ab12cd34ef56
bash
php artisan cardinal:deploy --sha=abc123 --branch=main