Core
Custom Drivers
Delivering a notification somewhere this package does not know about — the contract, and where the driver is registered.
On this page
Slack, a log line, a websocket of your own, a test spy: a driver is one small interface, and the calling code never learns which one answered. This is the seam that keeps every notification in the framework deliverable anywhere.
Custom Drivers
Implement the NotificationDriver contract — its single send() method receives the notification and (optionally) the Livewire component in scope:
use NyonCode\WireCore\Notifications\Contracts\NotificationDriver;use NyonCode\WireCore\Notifications\Notification; class SlackDriver implements NotificationDriver{ public function send(Notification $notification, mixed $livewireComponent = null): void { Http::post('https://hooks.slack.com/...', [ 'text' => $notification->title . ': ' . $notification->message, ]); }}
Register it as the global default in a service provider (boot()):
use NyonCode\WireCore\Notifications\NotificationManager; NotificationManager::setDefaultDriver(new SlackDriver());
Or use it for a single component/call without changing the global default:
$this->setNotificationDriver(new SlackDriver()); // per-component (trait)NotificationManager::send($notification, new SlackDriver()); // per-call
Related
- Notifications — the object a driver receives
- Toasts and Persistent Notifications — the two shipped drivers
- Plugins — registering a driver from a package
- Configuration — naming the default driver