jmpatricio/notifications
Composer 安装命令:
composer require jmpatricio/notifications
包简介
Notifications package for Laravel
关键字:
README 文档
README
Laravel 4.2.x Package
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.
Instalation
-
Run
composer require jmpatricio/notifications -
Add
Jmpatricio\Notifications\NotificationsServiceProviderto your service providers inconfig/app.php -
Instalation Done.
Basic usage
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>";
}
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache
- 更新时间: 2015-07-30