bhhaskin / pulse-laravel
Laravel integration package that exposes Pulse JS API endpoints.
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.2
README
bhhaskin/pulse-laravel provides a lightweight Laravel package that exposes API endpoints consumed by Pulse JS. It offers a drop-in route group with sensible defaults and can be extended to surface real-time metrics or diagnostic data for frontend dashboards.
Installation
composer require bhhaskin/pulse-laravel
The package is auto-discovered by Laravel so no manual service provider registration is required.
Configuration
Publish the configuration file to customize the route prefix or middleware stack applied to the beacon endpoint:
php artisan vendor:publish --tag=pulse-config
Key options inside config/pulse.php:
prefix: URL segment that prefixes all Pulse routes. Defaults topulse.middleware: Middleware applied to the Pulse route group. Defaults to theapistack.
Routes
Once installed the package registers the /pulse endpoint (unless you change the prefix) which is designed to be triggered via navigator.sendBeacon. The included controller currently acknowledges requests with an empty 204 No Content response, giving you a clean slate to hook into data sinks or job dispatching as Pulse evolves.
Data Flow
- Incoming batches are captured once in the
pulse_raw_batchestable; the batch processor validates each event and immediately materializes reporting records. - The processor keeps the downstream tables in sync:
pulse_clientskeeps per-client aggregates.pulse_sessionsties events back to a client session.pulse_devicesstores the first-party device fingerprint details (category, OS, viewport, capabilities, browser name/version, etc.) alongside the associated user agent.pulse_eventsholds query-friendly event records and keeps the originalpayloadblob intact so you can enrich analytics with any custom fields Pulse JS sends along.
- Incoming events are validated before persistence; malformed records are skipped so downstream tables stay clean.
- The package auto-loads its migrations; publish them via
php artisan vendor:publish --tag=pulse-migrationsif you need to override the schema.
Because the processing job implements ShouldQueue, make sure your queue worker is running in production, or set QUEUE_CONNECTION=sync if you prefer in-process execution.
Factories & Seeders
- Publish the package factories with
php artisan vendor:publish --tag=pulse-factoriesand seeders withphp artisan vendor:publish --tag=pulse-seedersif you want to customise or extend them inside your application. - You can quickly generate demo data by running the included seeder:
php artisan db:seed --class="\Bhhaskin\Pulse\Database\Seeders\PulseDatabaseSeeder". - When writing package-aware tests, the model factories are auto-loaded so you can use helpers like
PulseClient::factory()out of the box.
Testing
Run the test suite locally with:
composer test
The tests rely on orchestra/testbench to bootstrap a lightweight Laravel application context for package development.