Giter Club home page Giter Club logo

notificationapi-laravel's Introduction

Notification-api for Laravel

Package created to use the notification-api Service (https://www.notificationapi.com/) in Laravel projects

Official Doc for Notification Api: https://docs.notificationapi.com/

Installation

To get the latest version of notificationapi-laravel on your project, require it from "composer":

$ composer require nairanomura/notificationapi-laravel

Or you can add it directly in your composer.json file:

{
    "require": {
        "nairanomura/notificationapi-laravel": "1.0"
    }
}

Config

Register the provider directly in your app configuration file config/app.php:

'providers' => [
	// ...
	
	NairanOmura\NotificationApi\NotificationApiServiceProvider::class,
]

The following lines will be auto added in config/services.php by provider.

return [
   
    //...
    'notification-api' => [
        'key' => env('NOTIFICATION_API_KEY'),
        'secret' => env('NOTIFICATION_API_SECRET'),
    ]
];

So add the following environment variables in .env file to finish a configuration:

#.env
NOTIFICATION_API_KEY=clientID
NOTIFICATION_API_SECRET=clientSecret

This keys was offered by notification api after register an account

Using

Use Artisan to create a notification:

php artisan make:notification SomeNotification

Return [notification-api] in the public function via($notifiable) method of your notification:

public function via($notifiable)
{
    return ['notification-api'];
}

Add the method public function toNotificationApi($notifiable) to your notification:

//...

public function toNotificationApi($notifiable) 
{
    return [
        "notificationId" => "notification_example",
        "user" => [
            "id" => $notifiable->getAttribute('id'),
            "email" => $notifiable->getAttribute('email'),
        ],
        "mergeTags" => [
            "userName" => auth()->user()->name,
            "clickAction" => config('app.env')."/example"
        ]
    ];
}

example of notification send

*Attention: To call notification by the user model, the User model must be "Notifiable" Trait

    class User extends Authenticatable
    {
        use Notifiable;
        //...
#notify one user
$user->notify((new SomeNotification(..)));

#notify multiple users
Notification::send($users, new SomeNotification(..);

Extra: Helpers

After install and configure we can use the library calling the helper notification_api or class NotificationApiService

Example:

$data = [
  "notificationId" => "order_tracking",
  "user" => [
    "id" => "[email protected]",
    "email" => "[email protected]",
    "number" => "+15005550006"
  ],
  "mergeTags" => [
    "item" => "Krabby Patty Burger",
    "address" => "124 Conch Street",
    "orderId" => "1234567890"
  ]
];

$result = notification_api($data);
#or
$result = (new NotificationApiService)->send($data)

notificationapi-laravel's People

Contributors

nairanomura avatar

Watchers

 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.