---
title: "Owner models — Alerts for Laravel | Roundly"
description: "Implement HasNotifiablesForAlerts and use UsesHealthChecks on any model that owns checks and decides who is notified."
url: https://roundly-consulting.com/open-source/docs/alerts-for-laravel/owner-models
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Alerts for Laravel](https://roundly-consulting.com/open-source/docs/alerts-for-laravel.md)

# Owner models

The model that owns health checks decides who receives alert notifications. Implement HasNotifiablesForAlerts and use the UsesHealthChecks trait:

```php
use Closure;
use Illuminate\Database\Eloquent\Model;
use RoundlyConsulting\Alerts\Interfaces\HasNotifiablesForAlerts;
use RoundlyConsulting\Alerts\Traits\UsesHealthChecks;

class Team extends Model implements HasNotifiablesForAlerts
{
    use UsesHealthChecks;

    public function forEachNotifiableForAlerts(Closure $callback): void
    {
        $this->members()
            ->where('alerts_enabled', true)
            ->each(fn (Member $member) => $callback($member));
    }
}
```

forEachNotifiableForAlerts() hands every recipient in the default group to the callback. Recipients are sent notifications through Laravel’s Notification facade, so give them the Notifiable trait. The trait adds:

- healthChecks() and alerts() — morphMany relations to the owner’s scheduled checks and alerts.
- monitorCheck(string $check) — shortcut for Health::for($this)->monitor($check), the fluent scheduling builder (see Scheduling checks).
- monitor(ScheduleHealthCheckData $data) — shortcut for Health::for($this)->schedule($data); createHealthCheck(…) is its positional variant.
- notifiablesForAlertGroup(string $group) — via the bundled ResolvesAlertGroups trait, it returns the default group for any name. Override it for named escalation groups (see Escalation policies).

The scheduling shortcuts delegate to Health::for($this), so they behave exactly like the facade calls — and Health::fake() records them too.

## Any model can be an owner

Teams, tenants, projects or a single user — whatever should own its checks. A user can simply notify itself:

```php
use Closure;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use RoundlyConsulting\Alerts\Interfaces\HasNotifiablesForAlerts;
use RoundlyConsulting\Alerts\Traits\UsesHealthChecks;

// A user can own checks and receive its own alerts.
class User extends Authenticatable implements HasNotifiablesForAlerts
{
    use Notifiable;
    use UsesHealthChecks;

    public function forEachNotifiableForAlerts(Closure $callback): void
    {
        $callback($this);
    }
}
```

If a check fails for an owner that does not implement the interface, the run throws InvalidNotifiableForHealthCheck.

## Reading alerts

Alert has open() and recovered() scopes and relations back to its owner and health check:

```php
$team->healthChecks()->get();                         // scheduled HealthCheck rows
$team->alerts()->open()->get();                        // incidents still in progress
$team->alerts()->recovered()->latest('recovered_at')->first();

$alert = $team->alerts()->open()->first();

$alert->status;            // Status::Failed or Status::Warning
$alert->message;           // the result message that opened it
$alert->meta;              // the result meta as stored (plus 'muted' => true when muted)
$alert->escalation_level;  // 0 until a policy escalates it
$alert->triggered_at;      // Carbon
$alert->recovered_at;      // null while open
$alert->healthCheck;       // the scheduled HealthCheck row
$alert->notifiable;        // the owner
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/alerts-for-laravel.md)
