pestopancake / laravel-backpack-database-notifications
Database notifications interface for Laravel Backpack
Installs: 3 537
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 4
Forks: 6
Open Issues: 3
Requires
- backpack/crud: ^6.0
Requires (Dev)
- orchestra/testbench: ^6.0|^5.0|^4.0|^3.0
- phpunit/phpunit: ~8.0|~7.0|~9.0
- scrutinizer/ocular: ~1.7|~1.1
This package is auto-updated.
Last update: 2024-04-28 13:47:01 UTC
README
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).
Prerequisites
- 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
Installation
Backpack v5
composer require pestopancake/laravel-backpack-database-notifications
Backpack v4
composer require pestopancake/laravel-backpack-database-notifications:1.0.6
Usage
Publish the config file:
php artisan vendor:publish --provider="Pestopancake\\LaravelBackpackNotifications\\LaravelBackpackNotificationsServiceProvider" --tag=config
Show in side menu
Add a menu item to your 'resources/views/vendor/backpack/base/inc/sidebar_content.blade.php' by running:
php artisan backpack:add-sidebar-content "@include('backpack-database-notifications::sidebarMenuItem')"
Admin view
If you also have the Permission Manager package installed then 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.
Create a notification
Use the included generic notification
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 ));
Use in any other notification
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)
Troubleshooting
Notification not created
- 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)
Change log
See the changelog for more information on what has changed recently.
Todo
- Add unit tests
- translatable text
- notification preferences