rerout / laravel
Laravel integration for the Rerout branded-link API — service provider, facade, config, webhook controller, and events.
Requires
- php: ^8.2
- illuminate/http: ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0
- rerout/sdk: ^0.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- orchestra/testbench: ^8.0 || ^9.0 || ^10.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0 || ^11.0
This package is not auto-updated.
Last update: 2026-05-22 19:51:47 UTC
README
Laravel integration for the Rerout API.
Wraps rerout/sdk with a service
provider, facade, config file, a webhook controller, and Laravel events — so
short links, QR codes, analytics, and webhooks feel native in a Laravel app.
Install
composer require rerout/laravel
Requires PHP 8.2+ and Laravel 10, 11, or 12. The package auto-registers its
service provider and the Rerout facade via Laravel package discovery.
Publish the config file if you want to tweak defaults:
php artisan vendor:publish --tag=rerout-config
Configuration
Set these in your .env:
REROUT_API_KEY=rrk_… REROUT_WEBHOOK_SECRET=whsec_… REROUT_BASE_URL=https://api.rerout.co # optional REROUT_TIMEOUT=30 # optional, seconds
The published config/rerout.php also exposes the webhook tolerance window
and route settings — see the file's inline comments.
Usage
The client
The service provider binds a shared Rerout\Rerout singleton. Resolve it any
way Laravel allows — constructor injection, the container, or the facade.
use Rerout\Laravel\Facades\Rerout; use Rerout\Models\CreateLinkInput; $link = Rerout::links()->create(new CreateLinkInput( targetUrl: 'https://example.com/q4-sale', domainHostname: 'go.brand.com', code: 'q4', )); echo $link->shortUrl; // https://go.brand.com/q4
Constructor injection works too:
use Rerout\Rerout; public function __construct(private readonly Rerout $rerout) {}
The full client surface — links(), project(), qr() — is documented in
the base SDK README.
Verifying the API key
php artisan rerout:ping
Calls GET /v1/projects/me and prints the resolved project. Exits non-zero on
any API failure — handy for deploy smoke tests.
Webhooks
The package registers a POST route (default rerout/webhook, named
rerout.webhook) backed by a controller that:
- verifies the
X-Rerout-Signatureheader againstREROUT_WEBHOOK_SECRET, - returns 401 on a missing/invalid/expired signature,
- returns 400 on a body that is not a JSON object,
- dispatches a Laravel event and returns 200 otherwise.
Point your Rerout webhook endpoint at https://your-app.test/rerout/webhook.
Disable the bundled route (to mount the controller yourself) by setting
REROUT_WEBHOOK_ROUTE_ENABLED=false, or change the path with
REROUT_WEBHOOK_ROUTE_PATH.
Listen for the events:
Webhook type |
Event |
|---|---|
link.clicked |
Rerout\Laravel\Events\LinkClicked |
qr.scanned |
Rerout\Laravel\Events\QrScanned |
domain.failed |
Rerout\Laravel\Events\DomainFailed |
use Illuminate\Support\Facades\Event; use Rerout\Laravel\Events\LinkClicked; Event::listen(LinkClicked::class, function (LinkClicked $event) { // $event->payload is the decoded webhook body (array<string, mixed>) logger()->info('Link clicked', $event->payload); });
Each event carries the full decoded payload in its readonly $payload
property. Unknown event types still return 200 but dispatch nothing.
Error handling
Every client call throws Rerout\Exceptions\ReroutException on failure, with
a stable code(), HTTP status(), and isRateLimited() / isServerError()
flags. See the base SDK README
for the full list of error codes.
Local development
composer install composer test # PHPUnit + Orchestra Testbench composer analyse # PHPStan, level 9 composer format # php-cs-fixer
The composer.json includes a path repository pointing at ../php, so the
package builds against the local rerout/sdk checkout inside this workspace.
License
MIT — see LICENSE.