Skip to content

Laravel Notify Templates

Database-driven notification templates for Laravel. Admins edit the subject and body of every notification per channel, role and tenant; the package picks the right template, decides which channels a notification goes through and when, and logs what was actually delivered. It is not tied to any role package — who receives a notification is decided by your own resolver.

Every notification type is a class extending BaseNotify. The package takes care of everything around it:

  • Templates in the database — subject/body per notify type × channel slot × role × tenant, with an 8-level fallback chain down to defaults in code
  • Type registry — notify types auto-discovered from app/Notifications, with names, groups, tokens and defaults for an admin UI
  • Role subscriptions — which roles get which type, through which channels, with what delay
  • User preferences — a notifiable can turn a type off or narrow it to some channels; OTP-like types can be made non-optional
  • Channel resolution — one via() chain for built-in and custom channels (Telegram, SMS, …) through a single mapChannel() hook
  • Messenger buttons — link buttons under Telegram messages, multilingual, overridable per template
  • Delivery log — what was sent to whom, with provider delivery statuses (sent → delivered → read)
use Fomvasss\NotifyTemplates\Notifications\BaseNotify;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
final class OrderOrderedNotify extends BaseNotify implements ShouldQueue
{
use Queueable;
public function __construct(protected Order $order, protected string $roleKey) {}
public static function typeDefinition(): array
{
return [
'key' => 'OrderOrdered',
'name' => 'Order placed',
'group' => 'order',
'tokens' => [['key' => '[order:number]', 'name' => 'Order number']],
'defaults' => [
'mail' => ['subject' => 'Order placed', 'body' => 'Your order [order:number] has been received.'],
],
];
}
protected function prepareText(string $text, mixed $notifiable): string
{
return str_replace('[order:number]', $this->order->number, $text);
}
}
$user->notify(new OrderOrderedNotify($order, 'client'));

The mail goes out only if an active client subscription for OrderOrdered exists, with the subject and body from notify_templates (or the defaults above when there is no row).

Getting started

  1. Installation
  2. Configuration

Usage

  1. Notify types
  2. Sending notifications
  3. Recipients & role subscriptions
  4. Templates
  5. Channel resolution
  6. User preferences
  7. Custom channels
  8. Messenger buttons
  9. Delivery log
  10. Multi-tenancy
  11. Multilingual templates
  12. Queues & Octane

Reference

  1. NotifyTemplates facade
  2. BaseNotify
  3. typeDefinition() keys
  4. Tables & models
  5. Contracts & resolvers
  6. Artisan & publishing

Upgrading