PHPackages                             jlorente/laravel-pushy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. jlorente/laravel-pushy

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

jlorente/laravel-pushy
======================

Laravel integration for the Pushy SDK including a notification channel

1.0.3(4y ago)210.2k↓34.6%1[1 issues](https://github.com/jlorente/laravel-pushy/issues)BSD-3-ClausePHPPHP &gt;=7.1.3

Since Dec 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jlorente/laravel-pushy)[ Packagist](https://packagist.org/packages/jlorente/laravel-pushy)[ RSS](/packages/jlorente-laravel-pushy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Pushy SDK for Laravel
=====================

[](#pushy-sdk-for-laravel)

Laravel integration for the [Pushy SDK](https://github.com/jlorente/pushy-php-sdk) including a notification channel.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

With Composer installed, you can then install the extension using the following commands:

```
$ php composer.phar require jlorente/laravel-pushy
```

or add

```
...
    "require": {
        "jlorente/laravel-pushy": "*"
    }
```

to the `require` section of your `composer.json` file.

Configuration
-------------

[](#configuration)

1. Register the ServiceProvider in your config/app.php service provider list.

config/app.php

```
return [
    //other stuff
    'providers' => [
        //other stuff
        \Jlorente\Laravel\Pushy\PushyServiceProvider::class,
    ];
];
```

2. Add the following facade to the $aliases section.

config/app.php

```
return [
    //other stuff
    'aliases' => [
        //other stuff
        'Pushy' => \Jlorente\Laravel\Pushy\Facades\Pushy::class,
    ];
];
```

3. Publish the package in order to copy the configuration file to the config folder.

```
$ php artisan vendor:publish --provider=Jlorente\\Laravel\\Pushy\\PushyServiceProvider
```

4. Set the api\_key in the config/pushy.php file or use the predefined env variables.

config/pushy.php

```
return [
    'api_key' => 'YOUR_SECRET_API_KEY',
    //other configuration
];
```

or .env

```
//other configurations
PUSHY_API_KEY=
PUSHY_NOTIFICATION_TTL=

```

Usage
-----

[](#usage)

You can use the facade alias Pushy to execute api calls. The authentication params will be automaticaly injected.

```
Pushy::api()->deviceInfo($token);
```

Notification Channel
--------------------

[](#notification-channel)

A notification channel is included in this package and allows you to integrate the Pushy send notifications service with the Laravel notifications.

### Formatting Notifications

[](#formatting-notifications)

If you want to send a notification to Pushy, you should define a toPushy method on the notification class. This method will receive a $notifiable entity and should return a Jlorente\\Laravel\\Pushy\\Notifications\\Messages\\PushyMessage instance or an array with the payload to be sent on the notification:

```
/**
 * Get the PushyMessage that represents the notification.
 *
 * @param  mixed  $notifiable
 * @return \Jlorente\Laravel\Pushy\Notifications\Messages\PushyMessage|array
 */
public function toPushy($notifiable)
{
    return (new PushyMessage)
                ->setData([
                    'eventName' => 'my_event_name'
                ])
                ->setTimeToLive(3600);
}
```

Once done, you must add the notification channel in the array of the via() method of the notification:

```
/**
 * Get the notification channels.
 *
 * @param  mixed  $notifiable
 * @return array|string
 */
public function via($notifiable)
{
    return [PushyChannel::class];
}
```

You can find more info about Laravel notifications in [this page](https://laravel.com/docs/5.6/notifications).

### Routing the Notifications

[](#routing-the-notifications)

When sending notifications via Pushy channel, the notification system will automatically look for a pushy\_token attribute on the notifiable entity. If you would like to customize the token of the device the notification is delivered to, define a routeNotificationForPushy method on the entity:

```
