Skip to content

Installation

  • PHP ^8.2
  • Laravel 10, 11, 12 or 13 (illuminate/support, illuminate/database, illuminate/notifications)
  • PostgreSQL, MySQL 8.0.13+ or SQLite

The migration creates unique indexes over COALESCE(...) expressions (functional key parts). MySQL supports them from 8.0.13; MariaDB does not support them at all.

Terminal window
composer require fomvasss/laravel-notify-templates

The service provider and the NotifyTemplates facade alias are registered by package auto-discovery.

Publish and run the migrations:

Terminal window
php artisan vendor:publish --tag=notify-templates-migrations
php artisan migrate

Each migration is published only if a file with the same name suffix is not in database/migrations yet, so running the command again after an upgrade publishes only the new ones.

MigrationCreates
create_notifytemplates_tablesnotify_templates, notify_role_subscriptions, notify_user_settings
create_notify_logs_tablenotify_logs — used only when the delivery log is enabled
add_content_to_notify_logs_tablenotify_logs.subject, notify_logs.body for 0.8.x installs; a no-op when the columns exist

Publish the config if you need to change anything in it (optional):

Terminal window
php artisan vendor:publish --tag=notify-templates-config

Publish the status label translations if you want to change them (optional):

Terminal window
php artisan vendor:publish --tag=notify-templates-lang

The package does not know your roles and users. If notifications are sent per role from event listeners, implement NotifyRoleResolverInterface and bind it — see Recipients & role subscriptions. The package itself never calls the resolver, so nothing breaks without a binding until your own code asks for it.

// AppServiceProvider::register()
$this->app->bind(
\Fomvasss\NotifyTemplates\Contracts\NotifyRoleResolverInterface::class,
\App\Services\AppNotifyRoleResolver::class,
);
Terminal window
php artisan notify:make OrderOrdered

This creates app/Notifications/OrderOrderedNotify.php. Fill in typeDefinition(), then create an active subscription for a role — nothing is sent for a regular type without one:

use Fomvasss\NotifyTemplates\Models\NotifyRoleSubscription;
NotifyRoleSubscription::create([
'role_key' => 'client',
'notify_key' => 'OrderOrdered',
'is_active' => true,
'channels' => ['mail'],
]);

Next: Notify types and Sending notifications.