Download the PHP package xjoc/laravel-notification-center without Composer

On this page you can find all versions of the php package xjoc/laravel-notification-center. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-notification-center

Laravel Notification Center

A headless notification center for Laravel — zero coupling to any UI package. It provides a central gateway, template management, per-channel admin settings, and per-user opt-out preferences for Laravel notifications, leaving presentation entirely up to you.

Notifications still flow through Laravel's native notification system. This package inserts itself as a gateway on the NotificationSending event: it decides whether a given notification may go out on a given channel, and injects the rendered template body (and subject) at send time.

Concept: two tiers

The center deliberately keeps two kinds of notification types side by side:

Every type belongs to a category (essential, transactional, alerts, marketing). The category drives gateway behaviour — see below.

Requirements

Installation

The service provider is auto-discovered via package discovery.

One-command install

This publishes the config, runs the package migrations, and runs an initial sync of your coded types. It is equivalent to running, in order:

Manual config publish

Required host tables (caveats)

This package leans on Laravel's native notification channels. Two things must exist in the host application, not in this package:

Database tables this package creates

The package migrations create five tables, all namespaced with the notification_ prefix:

Table Purpose
notification_types The notification types (coded + admin-created).
notification_settings Per-type, per-channel enabled state.
notification_templates Per-type, per-channel subject/body templates.
notification_user_preferences Per-notifiable, per-(type, channel) opt-out state.
notification_event_bindings Event-class → type bindings for the event listener.

These names are not configurable in v1, and the models run on your default database connection. Before installing, confirm your host app does not already own a table with one of these names (the most plausible overlaps are notification_settings and notification_templates). A per-package table prefix is intentionally deferred: adding it later defaults to today's names, so it is a backward-compatible addition, not a breaking change held back from v1. The package's own notifications table dependency (for the database channel) is the host's standard Laravel table, covered above.

Low-touch integration (not zero-touch)

There is no magic. To route one of your existing notifications through the center, do two small things:

  1. Implement the NotifiableNotification contract.
  2. Use the HasNotificationCenter trait.

Then dispatch it the normal Laravel way:

The trait provides via() (resolves to the type's supported channels), and toMail(), toDatabase()/toArray(), and toWhatsapp(), all of which read the template the gateway injected at send time.

Template injection + override-wins

At send time the gateway renders the type's stored template for the target channel and injects it into the notification via the single unified method:

Override-wins rule. If you define your own toMail() / toDatabase() / toWhatsapp() on the notification, your method wins — PHP method resolution puts your class method ahead of the trait. The center will still gate the send; it just won't supply the body. This is intentional: the trait is a convenience, not a cage.

If a channel has no injected template and no override, the trait throws MissingTemplateException. This means: the type exists and is allowed, but no template row exists for that channel. Create one via the admin Template API.

The central gateway (order of decisions)

For every outgoing notification, the package listens on Illuminate\Notifications\Events\NotificationSending and runs this exact sequence per channel:

  1. Not ours? If the notification does not implement NotifiableNotification, allow it untouched.
  2. Unknown type? If the type key is not registered in the DB, allow it untouched.
  3. Essential bypass. If the type's category is essential, inject the template and always allow — ignoring the master switch, the channel setting, and the user's opt-out. (See "Essential protection" under Security.)
  4. Master switch. If the type is disabled (is_enabled = false), block.
  5. Admin channel setting. If the per-channel NotificationSetting is disabled, block.
  6. User opt-out. If the user has opted out of this (type, channel), block.
  7. Allow. Render + inject the template, then allow the send.

Blocking a single channel does not block the others — the decision is made per channel.

Categories and the essential bypass

Category Gateway behaviour
essential Bypasses the gateway and is force-locked + force-enabled. Cannot be disabled by admin or opted out by users (e.g. OTP).
transactional Fully gated (master switch, channel setting, user opt-out).
alerts Fully gated.
marketing Fully gated.

Configuration

config/notification-center.php:

Key Default Purpose
admin_middleware ['auth:sanctum', 'role:admin'] Middleware for the admin routes.
user_middleware ['auth:sanctum'] Middleware for the user routes.
route_prefix 'notification-center' URL prefix for both route groups.
user_model 'App\Models\User' String class name (never autoloaded at config-parse time).
notifiable_models ['App\Models\User'] Allowlist of models permitted as dispatch recipients.
channels ['mail' => MailChannel::class, 'database' => DatabaseChannel::class, 'whatsapp' => WhatsappChannel::class] Map of channel key => driver class (implementing NotificationChannel). The registered keys are the authoritative admin-pickable list. Add a custom channel by adding a key => class entry here or calling ChannelRegistry::register() in a provider.
cache.enabled true Toggle the lookup cache. When false, every read hits the DB directly.
cache.store null Cache store name (null = default store).
cache.ttl 3600 Cache TTL in seconds.
cache.prefix 'notification-center' Cache key prefix.
templates.escape_html true When enabled, the mail driver escapes variable values in the body via e().
templates.on_missing_var 'empty' 'empty' (blank) or 'throw' (MissingVariableException) for unknown template variables.
types see below Tier-1 coded types synced via notification-center:sync.

Declaring coded types

Artisan commands

Command Description
notification-center:install Publish config, run migrations, then sync. One-shot setup.
notification-center:sync Sync the coded types from config into the DB.

notification-center:sync guarantees:

Sending notifications

Direct dispatch (your code)

Use Laravel's notification system as usual once your notification implements the contract and uses the trait:

Manual dispatch via the facade

When you don't have a dedicated notification class, dispatch by type key:

Signature:

This builds a GenericNotification and dispatches it through the gateway — so admin settings and user opt-outs still apply.

Event binding (no code changes at the call site)

Bind a domain event to one or more notification types and the center will dispatch automatically when that event fires. Your event must implement ProvidesNotificationContext:

Then bind the event to a type through the admin Event Bindings API. When the event fires, the center sends the bound type(s) to the event's recipients with the event's variables. The service provider registers listeners for every active binding at boot (guarded against the DB not being ready, e.g. during migrate).

Because bindings are read at boot, a binding created at runtime takes effect on the next boot. Flush the binding cache after creating one (the admin API does this) and, in a long-running worker, plan for the listener registration to occur on the next process start.

API endpoints

All routes are JSON. The prefix is route_prefix from config (default notification-center). Route-model binding resolves {type} to a NotificationType and {binding} to a NotificationEventBinding.

Admin API

Group prefix: {route_prefix}/admin · middleware: admin_middleware · route-name prefix: notification-center.admin.

Method URI Name Action
GET types types.index List all types (with settings).
POST types types.store Create an admin type. Essential forces lock + enabled. Creates settings. 201.
PATCH types/{type} types.update Update name / supported channels / enabled. Disabling essential or locked → 422.
POST types/{type}/dispatch types.dispatch Dispatch this type to resolved recipients. 202.
GET types/{type}/templates types.templates.index List the type's templates.
PUT types/{type}/templates/{channel} types.templates.update Upsert a template for a channel (201 created / 200 updated).
GET types/{type}/event-bindings types.event-bindings.index List the type's event bindings.
POST types/{type}/event-bindings types.event-bindings.store Bind an event class to the type. 201.
DELETE event-bindings/{binding} event-bindings.destroy Remove a binding. 204.
GET settings settings.index Overview of all types + their per-channel settings.
GET channels channels.index Read-only list of registered channel keys (admin-pickable options). Never creates/modifies channels.

Dispatch request body shape:

recipients.model must be present in the notifiable_models allowlist (validated), otherwise the request is rejected with 422. channels must be a subset of the type's supported channels; null/omitted dispatches on all supported channels.

User API

Group prefix: {route_prefix}/user · middleware: user_middleware · route-name prefix: notification-center.user.

Method URI Name Action
GET preferences preferences.index The authenticated user's per-type, per-channel opt-out state.
PUT preferences/{type}/{channel} preferences.update Set opted_out for a (type, channel). Essential type → 403.

preferences returns, for each type and supported channel, an entry of the form { type_id, type_key, channel, opted_out, locked } where locked is true for essential types. Updating an essential type is forbidden (403).

Caching

Type, setting, template, supported-channel, and event-binding lookups are cached to keep the gateway cheap on the hot path. Behaviour:

Security

v1 caveats (honest limitations)

Development

This package uses spatie/laravel-package-tools and is tested against Laravel 12 and 13 on PHP 8.2–8.4.

Package structure

License

The MIT License (MIT). See LICENSE for details.


All versions of laravel-notification-center with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^12.0 || ^13.0
spatie/laravel-package-tools Version ^1.92
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package xjoc/laravel-notification-center contains the following files

Loading the files please wait ...