Package Data | |
---|---|
Maintainer Username: | jmpatricio |
Maintainer Contact: | jmpatricio@gmail.com (Joao Patricio) |
Package Create Date: | 2015-07-30 |
Package Last Update: | 2015-07-31 |
Language: | PHP |
License: | Apache 2 |
Last Refreshed: | 2024-12-22 03:02:12 |
Package Statistics | |
---|---|
Total Downloads: | 4 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package provides an abstract layer to manage notifications (eg. email notifications) in Laravel Framework, fired by triggers. This package was developed to work with Laravel 4.2.x but it will work with 5.1 LTS.
Run composer require jmpatricio/notifications
Add Jmpatricio\Notifications\NotificationsServiceProvider
to your service providers in config/app.php
Instalation Done.
Create the trigger
$notificationsManager = new \Jmpatricio\Notifications\Manager();
$trigger = $notificationsManager->getTriggerRepository()->add('user.newRegistration', 'When the user register');
Once we have the trigger instace created, we can create an action to be fired.
An action have a configuration, which depends of the notification provider.
$configuration = [
'view' => 'emails/newUserRegistration',
'fromEmail' => 'noreply@mywebsite.dev',
'fromName' => 'Notifications',
'toEmail' => 'some@email.dev',
'toName' => 'Staff user',
'subject' => 'New user registered!'
];
$configuration = \Jmpatricio\Notifications\Providers\Configuration::createFromArray($configuration);
Now we have the desired configuration. Let's create the action for this trigger
$notificationsManager->getActionRepository()->add($trigger, 'email', $configuration);
At this point we already have the action configured to run every time the trigger user.newRegistration
is fired.
This is an example to fire the trigger:
// Payload will be the new user object This is only an example
$payload = new stdClass();
$payload->name = 'John';
try {
$notificationsManager->fire($trigger->slug, $payload);
} catch (\Jmpatricio\Notifications\Exceptions\ConfigurationNotValidException $e){
echo "<pre>";
print_r($e->getErrors());
echo "</pre>";
}