Skip to content

Notification

Notification carries Domain data for a Laravel notification representation.

Generated facts

Layer
domain
Generated path
app/Pulsar/Domain/{Domain}/Notifications/{Name}.php
Generator command
make:notification
Workflow method
None
Stability
Current manifest surface (Pulsar 0.4.1)

Canonical example

Generated src/stubs/notification.stub — canonical synchronized stub.

<?php

namespace {{namespace}};

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class {{name}} extends Notification
{
    use Queueable;

    public function __construct(
        public readonly string $message,
    ) {
        // Carry DTOs or Value Objects when the notification needs structured domain data.
    }

    /**
     * @return list<string>
     */
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->subject('{{name}}')
            ->line($this->message);
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            'message' => $this->message,
        ];
    }
}

Responsibility

Notification owns the responsibility stated above; it must not absorb delivery, transaction, or unrelated cross-layer behavior.

Placement and dependencies

Keep this type in its generated Domain path. Domain is independent of delivery concerns; Infrastructure implements Domain-owned Contracts at its boundary.

Workflow and tests

Notification is consumed by the owning Domain or Service workflow and returns a delivery-neutral result. Test its direct contract, its rejected boundary cases, and the caller or callee that proves the rule in application flow.

Three pitfalls

  1. ❌ Prohibited: move this responsibility into a neighboring type merely because it is nearby.
  2. ✅ Correct: keep the generated placement and depend only on the documented layer direction.
  3. ✅ Correct: test the boundary through the caller and the return or side effect visible to its callee.

Related reading

Read architecture placement for shared rationale and follow this page’s related concept links for the adjacent responsibility.

Boundaries

❌ Prohibited: Do not promise guaranteed external delivery from a Notification alone.

✅ Correct: Use Listener and delivery rules to orchestrate external effects.