### Install and publish migrations Source: https://github.com/roundly-consulting/alerts-for-laravel/blob/main/README.md Install the package via Composer, publish the migrations, and run them. Requires PHP 8.4 and Laravel 12 or 13. Set ALERTS_KEY_TYPE before migrating if owner models use UUID/ULID keys. ```bash composer require roundly-consulting/alerts-for-laravel php artisan vendor:publish --tag="alerts-migrations" php artisan migrate ``` -------------------------------- ### Implement HasNotifiablesForAlerts on owner model Source: https://github.com/roundly-consulting/alerts-for-laravel/blob/main/README.md Let the owner model decide who gets notified by implementing HasNotifiablesForAlerts and using the UsesHealthChecks trait. The forEachNotifiableForAlerts method must iterate over notifiable entities. ```php use Closure; use RoundlyConsulting\Alerts\Interfaces\HasNotifiablesForAlerts; use RoundlyConsulting\Alerts\Traits\UsesHealthChecks; final class Team extends Model implements HasNotifiablesForAlerts { use UsesHealthChecks; public function forEachNotifiableForAlerts(Closure $callback): void { $this->members->each(fn (User $member) => $callback($member)); } } ``` -------------------------------- ### Monitor a check for an owner Source: https://github.com/roundly-consulting/alerts-for-laravel/blob/main/README.md Monitor a check for a specific owner. A failure opens an alert and notifies the team; a recovery closes it. Use everyFiveMinutes, failAfter, and save to configure. Also shows running a check now and checking overall health. ```php Health::for($team)->monitor(HttpPingCheck::class) ->everyFiveMinutes() ->failAfter(3) // open an alert only after 3 failures in a row ->save(); Health::for($team)->run(HttpPingCheck::class); // or run it now: a CheckResult Health::report()->isHealthy(); // bool, across every scheduled check ``` -------------------------------- ### Register health checks Source: https://github.com/roundly-consulting/alerts-for-laravel/blob/main/README.md Register built-in checks in a service provider's boot() method. The built-ins ship a default notification. Use DatabaseCheck and HttpPingCheck with timeout and slowerThan options. ```php use RoundlyConsulting\Alerts\Checks\DatabaseCheck; use RoundlyConsulting\Alerts\Checks\HttpPingCheck; use RoundlyConsulting\Alerts\Facades\Health; Health::check(DatabaseCheck::make()); Health::check(HttpPingCheck::make('https://api.example.com')->timeout(5)->slowerThan(800)); ```