Laravel Notify is a package that lets you add custom notifications to your Laravel >= 8 projects.
A diverse range of notification design is available.
Note This fork is intended to solve a common problem of the original Laravel Notify code polluting user code space.
- This package is a forked replacement for the original mckenziearts/laravel-notify package because of a known collision issue, so you must add this repo to your
composer.json
repositories key, like below:
{
"repositories": {
"laravel-notify": {
"type": "vcs",
"url": "https://github.com/damms005/laravel-notify"
}
}
}
- Require package using Composer
composer require mckenziearts/laravel-notify
- Publish the configuration file and assets by running:
Note The
--force
option is completely optional
php artisan vendor:publish --provider="Mckenziearts\Notify\LaravelNotifyServiceProvider" --force
- Finally, include this package's blade views as part of files Tailwind should build styles for, by updating the
content
property of your app's Tailwind config filetailwind.config.js
:
module.exports = {
content: [
...
./vendor/mckenziearts/laravel-notify/resources/views/**/*.blade.php",
],
}
- Ensure Alpine is loaded on any page where you want to use this Laravel Notify package. You can use the official CDN to quickly include Alpine:
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
- Add scripts links with
@notifyJs
- Include notify partial to your master layout:
<x:notify-messages />
- Use
notify()
helper function inside your controller to set a toast notification for info, success, warning or error
Frontend blade:
<!doctype html>
<html>
<head>
<title>Laravel Notify</title>
</head>
<body>
...
<x:notify-messages />
@notifyJs
</body>
</html>
In a controller, before you perform a redirect, call the notify
method with a message.
public function store()
{
notify()->success('Laravel Notify is awesome!');
return Redirect::home();
}
Laravel Notify actually display 5 types of notifications
toast
notification, (The default notification for Laravel Notify)
notify()->success('Welcome to Laravel Notify ⚡️') or notify()->success('Welcome to Laravel Notify ⚡️', 'My custom title')
connectify
notification, example of basic usage
connectify('success', 'Connection Found', 'Success Message Here')
drakify
(😎) notification, displays an alert only
drakify('success') // for success alert
or
drakify('error') // for error alert
smilify
notification, displays a simple custom toast notification using the smiley (😊) emoticon
smilify('success', 'You are successfully reconnected')
emotify
notification, displays a simple custom toast notification using a vector emoticon
emotify('success', 'You are awesome, your data was successfully created')
If you have a specific notification that is used across multiple different places in your system, you can define it as a preset notification in your config file. This makes it easier to maintain commonly used notifications in one place. Read how to define preset messages in the Config section below.
As an example, to use a preset notification you have defined called 'common-notification', use the following:
notify()->preset('common-notification')
You can override any of the values that are set in the config if you need to. For example, this could be useful if you have a common notification across, but you want to change the icon in one particular place that it's used without having to manually write out a new notification.
To do this, simply pass in an array that has the key of the attribute that you want to override and the value you want to override it with.
As an example, we could override the 'title' of our 'common-notification' by using the following:
notify()->preset('common-notification', ['title' => 'This is the overridden title'])
Config file are located at config/notify.php
after publishing provider element.
Some awesome stuff. To active dark mode
update the theme
config, or add global variable NOTIFY_THEME
on your .env file
'theme' => env('NOTIFY_THEME', 'dark'),
You can define preset notifications in the config file using the following structure:
'preset-messages' => [
'user-updated' => [
'message' => 'The user has been updated successfully.',
'type' => 'success',
'model' => 'connect',
'title' => 'User Updated',
],
'user-deleted' => [
'message' => 'The user has been deleted successfully.',
'type' => 'success',
'model' => 'connect',
'title' => 'User Deleted',
],
],
The example above shows the config for two preset notifications: 'user-updated' and 'user-deleted'.
Please see the changelog for more information on what has changed recently.
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email author email instead of using the issue tracker.
If you use and enjoy Laravel Notify you can encourage the author by
- Donating today!.
- Star the project ⭐.
- Charlie J - (10,00 $ USD) -
Donation made with love by Charlie from United Kingdom
- 9 October 2020
license. Please see the license file for more information.