Basics
By default, MoonShine uses Laravel Database Notification, but we use abstractions that can be easily replaced.
If you need to add notifications to the MoonShine notification center, use the MoonShineNotification
class.
Directly via the static method send()
:
use MoonShine\Laravel\Notifications\MoonShineNotification;use MoonShine\Laravel\Notifications\NotificationButton;use MoonShine\Support\Enums\Color; MoonShineNotification::send( message: 'Notification text', // Optional button button: new NotificationButton('Click me', 'https://moonshine.cutcode.dev', attributes: ['target' => '_blank']), // Optional administrator IDs (default for all) ids: [1,2,3], // Optional icon color color: Color::GREEN, // Optional icon icon: 'information-circle');
Or via DI
:
use MoonShine\Laravel\Contracts\Notifications\MoonShineNotificationContract; public function di(MoonShineNotificationContract $notification){ $notification->notify( 'Hello' );}
Settings
During the installation of MoonShine, you have the option to choose whether you want to use notifications and Database Notification
.
Additionally, you can change these settings later through the configuration:
'use_notifications' => true,'use_database_notifications' => true,
$config ->useNotifications() ->useDatabaseNotifications();
Component
The component Notifications is used to display notifications, which you can replace with your own through Layout.
Custom Notifications
MoonShine is flexible and everything can be replaced with your own implementations. For notifications, you need to implement the interfaces:
MoonShineNotificationContract
NotificationItemContract
NotificationButtonContract
(optional)
Then, in the ServiceProvider
, replace the implementation with your own:
public function boot(): void{ $this->app->singleton( MoonShineNotificationContract::class, MyNotificationSystem::class );}
WebSocket
A ready-made implementation of notifications via WebSocket is available in the Rush package.