Package Data | |
---|---|
Maintainer Username: | skovachev |
Maintainer Contact: | contact@stefankovachev.com (Stefan Kovachev) |
Package Create Date: | 2013-10-01 |
Package Last Update: | 2014-10-13 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-15 03:02:52 |
Package Statistics | |
---|---|
Total Downloads: | 25 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 8 |
Total Watchers: | 6 |
Total Forks: | 6 |
Total Open Issues: | 0 |
Some projects require user notifications to be sent out. In many cases there are multiple ways to notify an user about an event. This package makes it easier to send notifications using different notification channels.
You'll need to add the package to you composer.json
file.
"require-dev": {
"skovachev/notifier": "dev-master"
}
Then you need to run composer install
to download the package contents and update the autoloader.
Once it's installed you will need to register its service provider with your application. Open up app/config/app.php
and add the following update your providers
key.
'providers' => array(
'Skovachev\Notifier\ServiceProvider',
)
You'll also need to update your aliases
key as well.
'aliases' => array(
'Notifier' => 'Skovachev\Notifier\Facade',
)
That's it.
The package provides two ways of sending a notification out of the box: SMS and Email. SMS uses the Twilio SDK while Email uses the built in mailing functionality of Laravel.
To send a notification using both notifiers you need to do the following:
$notification = Notifier::createNotification($user, $view); // create notification with 1. user to be notifier and 2. view template
// set data needed to render the view template
$notification->setViewData($data);
// set subject of notification
$notification->setSubject('Your message');
// send notification
Notifier::sendNotification($notification);
By default Notifier will try to load the view template using the following path: notifications/<NOTIFIER_KEY>/<VIEW_TEMPLATE>
. For instance if we had a view named 'welcome_message' the path to the email templated would be notifications/email/welcome_message
and for the SMS - notifications/sms/welcome_message
.
The base folder for these templates can be changed in the package config.php
(See Settings for more information).
In some cases you may want to send a notification using only a subset of all available notification channels. In that case you can simply pass a list of Notifier keys along with the Notification object:
Notifier::sendNotification($notification, ['email']);
If you wanted to send a notification using just a single channel you can do that using the following syntax as well:
Notifier::sendEmailNotification($notification);
If you wanted to change some package settings you can do so by publishing the configuration:
php artisan config:publish skovachev/notifier
and editing the package's config.php
.
There you'll be able to set the base folder for notification templates, enable / disable notifiers, set notifier options and custom getters.
Getters are closures defined in the package's config.php
. They allow you to define how notifiers extract contact information from the passed used object. In the case of the Email Notifier you could define the values of the email and name attributes associated with the Email message.
Notifier is released under the MIT Licence. See the bundled LICENSE file for details.
Please do not hesitate to send suggestions and feature requests. Let's make this package awesome!