Download the PHP package multek/laravel-onesignal without Composer

On this page you can find all versions of the php package multek/laravel-onesignal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-onesignal

Laravel OneSignal

Laravel wrapper for the official OneSignal PHP SDK. Send push notifications through a clean, fluent API, and sync OneSignal users — identity, native properties, tags, and Email/SMS subscriptions — so they're reachable through OneSignal's own email/SMS messaging (dashboard campaigns, journeys). Also tracks custom events for analytics and segmentation.

Features

Requirements

Installation

Publish the config file:

Add your credentials to .env:

Environment variables

Variable Default Description
ONESIGNAL_APP_ID — Your OneSignal App ID (Dashboard → Settings → Keys & IDs)
ONESIGNAL_REST_API_KEY — REST API key used for server-side calls
ONESIGNAL_ENABLED true Master switch. false (or an empty ONESIGNAL_APP_ID) turns every call into a no-op
ONESIGNAL_TRACK_EVENTS false Enables trackEvent()/trackOneSignalEvent(). Custom events are rejected with a 403 on OneSignal's Free plan — leave this off unless your plan supports them
ONESIGNAL_QUEUE default Queue name for async operations (syncToOneSignalAsync(), deleteFromOneSignalAsync(), onesignal:backfill). Requires QUEUE_CONNECTION=sync in .env to run synchronously
ONESIGNAL_SYNC_MODEL auth provider model, then App\Models\User Fully-qualified model class used by onesignal:backfill. Only set it when your syncable model isn't the authenticated user, e.g. App\Models\Customer

ONESIGNAL_ORGANIZATION_API_KEY is also available for app-level management calls; most projects won't need it.

Client-side setup (web & mobile)

This package sends notifications and syncs user data, but push subscriptions can only be created on the device itself — by OneSignal's web or mobile SDKs. Both halves share one OneSignal app, and merge into one user by using the same external_id (what getOneSignalExternalId() returns) in every SDK's login() call.

See docs/client-sdk-integration.md for the full walkthrough: Web SDK setup, mobile setup (including apps that wrap your site in a WebView, where web push does not work), and the rules that keep a multi-SDK setup consistent.

Zero-config local dev

The package is safe to leave unconfigured. If ONESIGNAL_APP_ID is empty, or ONESIGNAL_ENABLED=false is set explicitly, OneSignalManager::isEnabled() returns false and every write operation (createUser, updateUser, deleteUser, sendNotification, trackEvents, syncToOneSignalAsync()'s dispatch) becomes a no-op that writes a debug-level log line instead of calling the API. This means:

The HasOneSignal trait

Add the trait to any Eloquent model you want to sync to OneSignal:

Contract (all overridable, all have sane defaults):

Method Default Notes
getOneSignalExternalId(): string $this->getKey() Identity used for every OneSignal call
getOneSignalEmail(): ?string $this->email Becomes a native Email subscription, not a tag
getOneSignalPhone(): ?string $this->phone Becomes a native SMS subscription, not a tag. Must be E.164 (e.g. +5511999999999); non-conforming values are omitted with a warning log instead of failing the sync
getOneSignalLanguage(): ?string null ISO 639-1 (pt, en) — native property
getOneSignalTimezone(): ?string null IANA id (America/Sao_Paulo) — native property
getOneSignalCountry(): ?string null ISO 3166-1 alpha-2 (BR, US) — native property
getOneSignalTags(): array built from config('onesignal.default_tags') Custom segmentation tags only — plan-limited (Free 2 / Growth 10 / Professional 100)

Identity fields (email, phone, language, timezone, country) are never auto-written as tags — only getOneSignalTags() controls tags.

Sync methods:

Both *Async() methods check OneSignalManager::isEnabled() before dispatching — when the package is disabled, no job is queued at all (not even a no-op job). Both jobs retry 3× with a [10, 60, 300]-second backoff, so a transient OneSignal 5xx doesn't silently orphan a profile.

Keeping OneSignal in sync automatically

That is the whole integration. No field list, no wasChanged() guard, no enablement check, no queue configuration. On every save the observer asks oneSignalPayloadChanged() — which compares the payload built from the model's current attributes against the one built from its original attributes — and dispatches a sync only when they differ. Add a tag to getOneSignalTags() and it is covered the same day, with no list to update.

What the observer covers:

Change Covered
The user's own attributes (email, subscription_plan, …) Yes
The user's foreign key (role_id 1 → 2) Yes
A related row's content (roles.name renamed, user untouched) No
Many-to-many attach/detach No

The last two fire no event on the user, so no user-side mechanism can see them — a hand-maintained field list misses them too. For tags derived from a relation, observe the related model:

And schedule the backfill as reconciliation rather than keeping it for emergencies:

An observer is incremental and best-effort — mass updates (User::where(...)->update()) fire no events at all. Backfill is the other half. Together they are complete; either alone is not. This is safe rather than merely hedged because the diff only decides when to talk to OneSignal, never what gets sent — anything missed is corrected in full by the next sync from any cause. SyncUserToOneSignal re-reads the model from the database when it runs (SerializesModels stores only the class and key, on every queue connection including sync), so a sync always sends current state, never a dispatch-time snapshot.

Escape hatches, in increasing order of control: omit the attribute and call User::observe(OneSignalObserver::class) yourself; write your own observer using the public oneSignalPayloadChanged(); call syncToOneSignalAsync() by hand.

With SoftDeletes the observer already does the right thing: a soft delete keeps the OneSignal profile, forceDelete() removes it, and restored resyncs. (The "Deleting on model deletion" section below recommends hooking forceDeleted for a hand-rolled deleted observer — that advice is for your own hooks; the shipped OneSignalObserver already handles the soft-delete/force-delete distinction via isForceDeleting() and needs nothing extra.)

Transactions: both SyncUserToOneSignal and DeleteUserFromOneSignal are afterCommit. saved and deleted can fire inside an open DB::transaction(); without this, a worker could pick up the job and act on the row before the transaction commits — or after it rolls back. Dispatching from inside a transaction waits for the commit instead of racing it; dispatching with no open transaction is unaffected.

Deleting on model deletion

This section is for a hand-rolled deleted hook of your own. If you're using the shipped OneSignalObserver (see above), it already distinguishes soft deletes from force deletes correctly — nothing here is needed on top of it.

deleteFromOneSignalAsync() captures the external id eagerly, so it is safe to call from a deleted hook where the row is already gone:

Two things to know:

Deleting by id, with no model in hand (admin tooling, GDPR/LGPD erasure of an already-removed row):

Sending notifications

Facade one-liners

Fluent builder

The builder also supports toUsers(), toSegments(), excludeSegments(), withFilters(), subtitle(), addButton(), sendAfter(), throttle(), priority(), ttl(), template(), name(), and raw() (escape hatch to the underlying SDK Notification object).

Laravel notification channel

Models routing notifications use routeNotificationForOnesignal(), provided automatically by HasOneSignal (returns getOneSignalExternalId()).

Raw SDK access

Custom events

Event tracking is gated by ONESIGNAL_TRACK_EVENTS (default false). OneSignal's Free plan rejects custom events with a 403 — leave the flag off there. When the flag is off, trackEvent()/trackEvents() no-op with a debug log instead of calling the API, so it's safe to call unconditionally from application code once your plan supports events.

Backfill

Sync every record of a configured model to OneSignal in chunks:

No configuration needed on a standard Laravel app: the command resolves the model from onesignal.sync_model, falling back to your auth provider model (config('auth.providers.users.model')) and then to App\Models\User. Set ONESIGNAL_SYNC_MODEL only when the model you sync isn't the authenticated user.

The resolved class must use HasOneSignal. The command exits early with an error if it doesn't exist or lacks the trait, and warns (without failing) if OneSignal is disabled.

Testing

Run the mocked unit/feature suite (no network calls, safe in CI):

Live suite

tests/Live exercises the full user lifecycle (create, get, re-sync/upsert, update tags, track event, delete) against the real OneSignal API. It's skipped automatically unless both env vars are set:

Use a dedicated OneSignal test app — the suite creates and deletes real users.

Configuration

See config/onesignal.php for the full option reference, including default tags, queue name, sync model, and organization API key.

License

MIT


All versions of laravel-onesignal with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/notifications Version ^11.0|^12.0|^13.0
onesignal/onesignal-php-api Version ^5.0@beta
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package multek/laravel-onesignal contains the following files

Loading the files please wait ...