### Install laravel-onesignal via Composer Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-onesignal ``` -------------------------------- ### Manage templates with OneSignal facade Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md List, get, and create templates. ```php $templates = OneSignal::templates()->list(limit: 10, offset: 0); $template = OneSignal::templates()->get('template-id'); OneSignal::templates()->create('Welcome', message: 'Hi there!', heading: 'Welcome!'); ``` -------------------------------- ### Get app with OneSignal facade Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Get the current app information. ```php $app = OneSignal::app()->get(); ``` -------------------------------- ### Manage users with OneSignal facade Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Get, create, and delete users. The get method accepts an external ID or a OneSignal ID with the identifier type. ```php $user = OneSignal::users()->get('user-1'); $user = OneSignal::users()->get('onesignal-id', 'onesignal_id'); OneSignal::users()->create(externalId: 'user-1', email: 'jane@example.com', tags: ['plan' => 'pro']); OneSignal::users()->delete('user-1'); ``` -------------------------------- ### Send and manage notifications with OneSignal facade Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Send, list, get, and cancel notifications. Targeting precedence when multiple options are given: segments > emails > playerIds > aliases > the default 'Subscribed Users' segment. ```php use JeffersonGoncalves\LaravelOnesignal\Facades\OneSignal; // Defaults to the "Subscribed Users" segment OneSignal::notifications()->send('Hello world!', heading: 'Hi there'); // Target specific segments OneSignal::notifications()->send('Hello!', segments: ['Active Users']); // Target specific emails, player IDs or aliases OneSignal::notifications()->send('Hello!', emails: ['jane@example.com']); OneSignal::notifications()->send('Hello!', playerIds: ['player-id']); OneSignal::notifications()->send('Hello!', aliases: ['external_id' => ['user-1']], channel: 'push'); $notifications = OneSignal::notifications()->list(limit: 10, offset: 0); $notification = OneSignal::notifications()->get('notification-id'); OneSignal::notifications()->cancel('notification-id'); ``` -------------------------------- ### Publish laravel-onesignal config Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Publish the package configuration file. ```bash php artisan vendor:publish --tag=laravel-onesignal-config ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Runs the test suite for the package. Use this command to execute all tests defined in the project. ```bash composer test ``` -------------------------------- ### laravel-onesignal config file Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Configuration file for the package, reading the app ID and REST API key from environment variables. ```php // config/laravel-onesignal.php return [ 'app_id' => env('ONESIGNAL_APP_ID', ''), 'rest_api_key' => env('ONESIGNAL_REST_API_KEY', ''), ]; ``` -------------------------------- ### Manage segments with OneSignal facade Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md List, create, and delete segments. The default filter for segment creation is session_count > 0. ```php $segments = OneSignal::segments()->list(limit: 10, offset: 0); // Default filter: session_count > 0 OneSignal::segments()->create('Active Users'); OneSignal::segments()->create('VIPs', [ ['field' => 'tag', 'key' => 'vip', 'relation' => '=', 'value' => 'true'], ]); OneSignal::segments()->delete('segment-id'); ``` -------------------------------- ### Set OneSignal credentials in .env Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Set your OneSignal App ID and REST API key in the .env file. Both are found under Settings > Keys & IDs in the OneSignal dashboard. ```env ONESIGNAL_APP_ID=your-app-id ONESIGNAL_REST_API_KEY=your-rest-api-key ``` -------------------------------- ### Catch OneSignalException with error body Source: https://github.com/jeffersongoncalves/laravel-onesignal/blob/main/README.md Handle non-2xx API responses. The exception exposes the decoded error body via errorBody(). ```php use JeffersonGoncalves\LaravelOnesignal\Exceptions\OneSignalException; try { OneSignal::notifications()->send('Hello!'); } catch (OneSignalException $e) { logger()->error($e->getMessage(), $e->errorBody()); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.