Coder Social home page Coder Social logo

notifier's Introduction

Notifier Build status

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.

Installation

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.

Usage

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);

Settings

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

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.

License

Notifier is released under the MIT Licence. See the bundled LICENSE file for details.

Contributions

Please do not hesitate to send suggestions and feature requests. Let's make this package awesome!

notifier's People

Contributors

skovachev avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.