PHP code example of redwebcreation / laravel-healthful

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

    

redwebcreation / laravel-healthful example snippets




use RWC\Healthful\Checks\DatabaseCheck;
use RWC\Healthful\Checks\QueueCheck;
use RWC\Healthful\Checks\SchedulerCheck;

return [
    /* The route that should return the health status */
    'route' => '/_/health',

    /* A list of checks to be performed. */
    'checks' => [
        DatabaseCheck::class,
    ]
];

use RWC\Healthful\Facades\Health;

Health::check();

use RWC\Healthful\Facades\Health;

Health::route()->name('healthcheck');

// app/HealthChecks/IsMondayCheck.php
use RWC\Healthful\Checks\Check;

class IsMondayCheck implements Check {
    public function passes() : bool{
        // Monday is never healthful.
        return !now()->isMonday();
    }
}

// config/healthful.php
return [
    'checks' => [
        // ...
        IsMondayCheck::class
    ]
    
];

use RWC\Healthful\Models\Heartbeat;

$heartbeat = Heartbeat::firstOrNew([
    'type' => 100 // any number above 100
]);

$heartbeat->updateTimestamps();
$heartbeat->save();

use RWC\Healthful\Checks\Check;
use RWC\Healthful\Models\Heartbeat;

class MyCheck implements Check {
    public function passes(): bool {
        $heartbeat = Heartbeat::query()
            ->where('type', 100)
            ->where('updated_at', '>=', now()->subMinutes(5))
            ->first();

        return $heartbeat !== null;
    }
}
bash
php artisan vendor:publish --tag="healthful-migrations"
bash
php artisan vendor:publish --tag="healthful-config"