Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ You can send a message based on a set of tags with the command
);
```

### How To Get The User ID ($userId)

To obtain the user ID, you must use the code below in the middle of the form, and it will be sent as OneSignalUserId, you can use it when logging in or ...

```php
@include('OneSignal::userid')
```
include is this input :
```html
<input type="hidden" name="OneSignalUserId" id="OneSignalUserId">
...

```

### Sending a Notification To A Specific User

After storing a user's tokens in a table, you can simply send a message with
Expand Down
15 changes: 15 additions & 0 deletions resources/view/userid.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<input type="hidden" name="OneSignalUserId" id="OneSignalUserId">
<script>
OneSignal.isPushNotificationsEnabled(function(isEnabled) {
if (isEnabled) {
// user has subscribed
OneSignal.getUserId( function(userId) {
var OneSignalUserId=document.getElementById('OneSignalUserId');
OneSignalUserId.innerText=userId;
});
}else{
var OneSignalUserId=document.getElementById('OneSignalUserId');
OneSignalUserId.innerText=null;
}
});
</script>
1 change: 1 addition & 0 deletions src/OneSignalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class OneSignalServiceProvider extends ServiceProvider
public function boot()
{
$configPath = __DIR__ . '/../config/onesignal.php';
$this->loadViewsFrom(__DIR__.'/../resources/views', 'OneSignal');

$this->publishes([$configPath => config_path('onesignal.php')], 'config');
$this->mergeConfigFrom($configPath, 'onesignal');
Expand Down