PHPackages                             kce/onesignal-laravel - 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. [API Development](/categories/api)
4. /
5. kce/onesignal-laravel

ActiveLibrary[API Development](/categories/api)

kce/onesignal-laravel
=====================

Onesignal wrapper for Laravel Framework.

1.0.2(5y ago)441.3k4[2 PRs](https://github.com/kadircanerergun/laravel-onesignal/pulls)PHPPHP &gt;=5.4.0CI failing

Since Sep 25Pushed 5y ago5 watchersCompare

[ Source](https://github.com/kadircanerergun/laravel-onesignal)[ Packagist](https://packagist.org/packages/kce/onesignal-laravel)[ RSS](/packages/kce-onesignal-laravel/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (7)Versions (6)Used By (0)

Laravel OneSignal
=================

[](#laravel-onesignal)

[![Build Status](https://camo.githubusercontent.com/55dec37061d971a2e4ffdaafd8baf0df1d97cd65584b4d7a1154ad9d9630cbb1/68747470733a2f2f7472617669732d63692e6f72672f6f7a6775726b792f6c61726176656c2d6f6e657369676e616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ozgurky/laravel-onesignal)

Send push notifications easily with [OneSignal](https://onesignal.com)
----------------------------------------------------------------------

[](#send-push-notifications-easily-with-onesignal)

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

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

[](#installation)

In order to add Laravel OneSignal to your project, just add

```
composer require kce/onesignal-laravel

```

Composer auto discovery will register the provider. If dont use it add the following lines to "config/app.php"

```
'providers' => [
        ...
        .
        .
        KCE\OneSignal\OneSignalServiceProvider::class
]
...
.
.,
'aliases' => [
    ...
    ..
    .
    'OneSignalClient' => KCE\OneSignal\Facades\OneSignalClient::class
]

```

Publish the configuration

```
php artisan vendor:publish --provider="KCE\OneSignal\OneSignalServiceProvider"

```

Usage
-----

[](#usage)

### Configuration

[](#configuration)

This package requires you to change the fields in the `config/onesignal.php` file:

```
return array (
    /*
     |--------------------------------------------------------------------------
     | One Signal App Id
     |--------------------------------------------------------------------------
     |
     | You can find in : Project > Settings > Key & ID's > ONESIGNAL APP ID
     |
     */
    'app_id' => env("ONESIGNAL_APP_ID", 'default_app_id'),

    /*
     |--------------------------------------------------------------------------
     | Rest API Key
     |--------------------------------------------------------------------------
     |
     | You can find in : Project > Settings > Key & ID's > REST API KEY
     |
     */
    'rest_api_key' => env("ONESIGNAL_REST_API_KEY", 'rest_api_key'),

    /*
     |--------------------------------------------------------------------------
     | User Auth Key
     |--------------------------------------------------------------------------
     |
     | You can find in : Profile > ACCOUNT & API KEYS > AUTH KEY
     |
     */
    'user_auth_key' => env("ONESIGNAL_USER_AUTH_KEY", 'user_auth_key'),
);
```

#### Send to ALL

[](#send-to-all)

Send notification to all subscribed devices

```
\KCE\OneSignal\Facades\OneSignalClient::sendToAll('Notification message');
```

#### Send to Country

[](#send-to-country)

Send notification to specific country

```
\KCE\OneSignal\Facades\OneSignalClient::sendToCountry('Notification message', 'TR'); // Country ISO Code
```

#### Send to Location

[](#send-to-location)

Send notification to a particular area-wide. Use radius in meters

```
\KCE\OneSignal\Facades\OneSignalClient::sendToLocation('Notification message', 10000, 37.4247, 41.33933); // Use Lat, Long and Radius
```

#### Send to single user or users.

[](#send-to-single-user-or-users)

Send notification to player ids.

```
\KCE\OneSignal\Facades\OneSignalClient::sendToUser('Notification message', "player_id"); // Single player id
```

or

```
\KCE\OneSignal\Facades\OneSignalClient::sendToUser('Notification message', ["player_id1", 'player_id2]); // Multiple player ids
```

#### Send to segment

[](#send-to-segment)

Send notification to one or more segments

```
\KCE\OneSignal\Facades\OneSignalClient::sendToSegment('Notification message', "segment");
//or
\KCE\OneSignal\Facades\OneSignalClient::sendToSegment('Notification message', ["segment", "segment2"]);
```

#### Send to Tags

[](#send-to-tags)

Send notification filter by tags

```
\KCE\OneSignal\Facades\OneSignalClient::sendToTags('Notification message', ["user_id", "=", 15]); //will send the notification to user that tagges as user_id 15
```

### Add Data and/or Title To Notifications

[](#add-data-andor-title-to-notifications)

```
\KCE\OneSignal\Facades\OneSignalClient::setTitle("Notification Title")->setData([
        'key' => 'value'
    ])->sendToAll("Example Message");
```

### Scheduling

[](#scheduling)

You can schedule notification for future date time.

```
\KCE\OneSignal\Facades\OneSignalClient::setSchedule("2018-10-29 10:00")->sendToAll("Cumhuriyet Bayramı Kutlu Olsun!");
```

#### Schedule based on User's Timezone

[](#schedule-based-on-users-timezone)

Notification will deliver at a specific time-of-day in each users own timezone.

```
\KCE\OneSignal\Facades\OneSignalClient::scheduleByUserTimezone("04:44PM")->sendToAll("This message will deliver based on user timezone on 04:44PM!");
```

### addTag / addOrTag

[](#addtag--addortag)

If you use addTag or addTags method it will put AND between tags. If you want to use multiple tags with "OR" connector, you should use addOrTag method.

```
$client = app('onesignal');
$client->addTag(['fav_color', 'green'])->addOrTag(['fav_color', 'red'])->sendToAll("Users like yellow or red");
```

### Send by First / Last Session

[](#send-by-first--last-session)

Typically filters has 3 parameters (key, relation, value) but some filters like last\_session, first session has their own value keys. You can add specific value key as 4th parameter. If you want to send notification by users last or first active time you can use addFilter method by value key.

```
$client = app('onesignal');
$client->addFilter('last_session', '>', '48', 'hours_ago')->sendToAll("Notification by last active"); // Users who last session time more than 48 Hours.
$client->addFilter('last_session', '', '48', 'hours_ago')->sendToAll("Notification by last active"); // Users who first session time more than 48 Hours.
$client->addFilter('first_session', '
