Easily add an admin interface for standard Laravel database notifications. This package includes:
- a sidebar item, with an optional notification count for the current user (refreshed with AJAX every second)
- an interface that shows the notifications in the database for the current user, with their (optional) action buttons;
The only thing left for you to do is to actually trigger notifications for your admins, wherever you want, using the standard Laravel syntax (example below).
- Have Laravel Backpack installed backpack/crud v4.0.* | 4.1.*
- Follow the steps for laravel's database notifications prerequisites, e.g:
php artisan notifications:table
php artisan migrate
- Have Permission Manager installed Laravel-Backpack/PermissionManager
composer require pestopancake/laravel-backpack-database-notifications
composer require pestopancake/laravel-backpack-database-notifications:1.0.6
Publish the config file:
php artisan vendor:publish --provider="Pestopancake\\LaravelBackpackNotifications\\LaravelBackpackNotificationsServiceProvider" --tag=config
Add a menu item to your 'resources/views/vendor/backpack/base/inc/sidebar_content.blade.php' by running:
php artisan backpack:add-menu-content "@include('backpack-database-notifications::sidebarMenuItem')"
With the Permission Manager package installed you can assign the permission 'notifications admin' to users for them to see admin functionality.
To change the permission name edit 'admin_permission_name' in the databasenotifications config file.
Currently users with the admin permission can see/dismiss notifications for all users.
use Pestopancake\LaravelBackpackNotifications\Notifications\DatabaseNotification;
$user = backpack_user();
$user->notify(new DatabaseNotification(
$type = 'info', // info / success / warning / error
$message = 'Test Notification',
$messageLong = 'This is a longer message for the test notification '.rand(1, 99999), // optional
$href = '/some-custom-url', // optional, e.g. backpack_url('/example')
$hrefText = 'Go to custom URL' // optional
));
The toArray method of the notification should be in this format:
return [
'type' => "info", // info / success / warning / error
'message' => "",
'message_long' => "", // optional
'action_href' => "", // optional, e.g. backpack_url('/example')
'action_text' => "", // optional
];
The type will affect the colour of the toast notification (if toasts are enabled in the config)
- Make sure the model you are notifying matches the model defined in your backpack config at backpack.base.user_model_fqn (found in config/backpack/base.php)
See the changelog for more information on what has changed recently.
- Add unit tests
- translatable text
- notification preferences