# Health Check Setup

[![documentation](https://img.shields.io/badge/documentation-forestgreen?style=flat-square)](https://spatie.be/docs/laravel-health/v1)
[![spatie/laravel-health](https://img.shields.io/badge/spatie/laravel--health-555555?style=flat-square&logo=github)](https://github.com/spatie/laravel-health)

Installation
-------------

```shell
composer require spatie/laravel-health
```

```shell
php artisan vendor:publish --tag="health-config"
php artisan vendor:publish --tag="health-migrations"
```

Configuration
--------------

```php title="app/Service/HealthCheckService.php"
// in app/Service/HealthCheckService.php

use Illuminate\Support\ServiceProvider;
use Spatie\Health\Checks\Checks\DatabaseCheck;
use Spatie\Health\Checks\Checks\DebugModeCheck;
use Spatie\Health\Checks\Checks\EnvironmentCheck;
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck;
use Spatie\Health\Facades\Health;

class HealthCheckService extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Health::checks([
            // https://spatie.be/docs/laravel-health/v1/available-checks/environment
            EnvironmentCheck::new()->unless($this->app->environment('local')),
            // https://spatie.be/docs/laravel-health/v1/available-checks/debug-mode
            DebugModeCheck::new()->unless($this->app->environment('local')),
            // https://spatie.be/docs/laravel-health/v1/available-checks/db-connection
            DatabaseCheck::new(),
            // https://spatie.be/docs/laravel-health/v1/available-checks/used-disk-space
            UsedDiskSpaceCheck::new(),
            // https://spatie.be/docs/laravel-health/v1/available-checks/queue
            // https://spatie.be/docs/laravel-health/v1/available-checks/schedule
        ]);
    }
}
```

```php title="routes/web.php"
// in routes/web.php

use Spatie\Health\Http\Controllers\HealthCheckResultsController;

Route::get('/up', HealthCheckResultsController::class);
```

```php title="routes/console.php"
// in routes/console.php
use Illuminate\Support\Facades\Schedule;

Schedule::command(\Spatie\Health\Commands\RunHealthChecksCommand::class)->everyMinute();
```

#### Custom Health Check Model

```php title="app/Model/HealthCheckResult.php"
// in app/Model/HealthCheckResult.php

use Illuminate\Database\Eloquent\Attributes\Table;
use Spatie\Health\Models\HealthCheckResultHistoryItem;

#[Table(name: 'HEALTH_CHECK')]
class HealthCheckResult extends HealthCheckResultHistoryItem
{
    //
}
```

```php title="config/health.php"
// in config/health.php

return [
    'result_stores' => [
        EloquentHealthResultStore::class => [
            'model' => HealthCheckResult::class,
        ],
    ],
];