PHPackages                             skaisser/laravel-lead - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. skaisser/laravel-lead

ActiveLibrary[Caching](/categories/caching)

skaisser/laravel-lead
=====================

A Laravel package for multi-layer lead persistence, visitor-isolated caching, webhook integrations, and progressive lead creation

v1.2.0(10mo ago)15MITPHPPHP ^8.1CI passing

Since Jun 24Pushed 10mo agoCompare

[ Source](https://github.com/skaisser/laravel-lead)[ Packagist](https://packagist.org/packages/skaisser/laravel-lead)[ RSS](/packages/skaisser-laravel-lead/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (3)Used By (0)

Laravel Lead Persistence
========================

[](#laravel-lead-persistence)

[![Tests](https://github.com/skaisser/laravel-lead/actions/workflows/tests.yml/badge.svg)](https://github.com/skaisser/laravel-lead/actions/workflows/tests.yml)[![Laravel](https://camo.githubusercontent.com/c5636cbc00edeb2fc30bc0a089aca31231cc9b87845c6d56b74fb9e2fc931b02/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825323025374325323031312e7825323025374325323031322e782d4646324432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://laravel.com)[![License](https://camo.githubusercontent.com/71e8fa31b305fcfce8777110a092199e97b276c376448d7de19fad179ed06edc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736b6169737365722f6c61726176656c2d6c6561642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/skaisser/laravel-lead)

A comprehensive Laravel package for multi-layer lead persistence, webhook integrations, and progressive lead creation. This package provides sophisticated tools for managing leads in your Laravel application with advanced features like encrypted storage, automatic fallbacks, and real-time synchronization.

Features
--------

[](#features)

- **🔄 Multi-layer Lead Persistence**: Automatic fallback chain (Redis → Session → Cookies → localStorage)
- **🪝 Webhook Integration**: Configurable webhooks with custom field mapping and retry logic
- **📱 Phone Formatting**: International phone number formatting with country-specific rules
- **💾 Progressive Lead Creation**: Create leads from query parameters before form submission
- **🔐 Encrypted Storage**: Secure lead ID encryption across all storage layers
- **🌐 JavaScript Integration**: Client-side lead storage with automatic synchronization
- **🔀 Lead Merging**: Intelligent merging of lead data from multiple sources
- **📊 UTM Tracking**: Automatic capture and storage of marketing parameters

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require skaisser/laravel-lead
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=lead-persistence-config
```

This will create a `config/lead-persistence.php` file where you can customize the package settings.

### Key Configuration Options

[](#key-configuration-options)

```
return [
    // The model class that represents leads
    'lead_model' => App\Models\Lead::class,

    // Storage layers configuration
    'use_session' => true,
    'use_cookies' => true,
    'cookie_name' => 'lead_id',
    'cookie_duration' => 525600, // 365 days

    // Encryption settings
    'encryption_enabled' => true,

    // Cache configuration
    'cache_prefix' => 'lead_',
    'cache_ttl' => 1800, // 30 minutes
];
```

Usage
-----

[](#usage)

### Basic Lead Persistence

[](#basic-lead-persistence)

```
use Skaisser\LaravelLead\Facades\LeadPersistence;

// Store a lead
$lead = Lead::create(['name' => 'John Doe', 'email' => 'john@example.com']);
LeadPersistence::storeLead($lead);

// Retrieve current lead (with automatic fallback)
$currentLead = LeadPersistence::getCurrentLead();

// Check if a lead exists
if (LeadPersistence::hasStoredLead()) {
    // Lead exists in storage
}

// Clear stored lead
LeadPersistence::clearStoredLead();
```

### Progressive Lead Creation

[](#progressive-lead-creation)

```
// Save lead data progressively (creates or updates)
$leadData = [
    'name' => request('name'),
    'email' => request('email'),
    'phone' => request('phone'),
    'country_code' => request('country_code'),
    'query_data' => request()->query(), // UTM parameters, etc.
];

$lead = LeadPersistence::saveLead($leadData);

// Update existing lead
$existingLead = LeadPersistence::getCurrentLead();
$updatedLead = LeadPersistence::saveLead($newData, $existingLead);
```

### Webhook Integration

[](#webhook-integration)

First, publish and run the migrations:

```
php artisan vendor:publish --tag=lead-persistence-migrations
php artisan migrate
```

Then use webhooks in your application:

```
use Skaisser\LaravelLead\Jobs\ProcessWebhookSubmission;
use Skaisser\LaravelLead\Models\Webhook;

// Create a webhook configuration
$webhook = Webhook::create([
    'name' => 'CRM Integration',
    'url' => 'https://api.crm.com/leads',
    'method' => 'POST',
    'headers' => ['Authorization' => 'Bearer token123'],
    'selected_fields' => ['name', 'email', 'phone', 'company'],
    'field_mapping' => [
        ['original_field' => 'name', 'custom_name' => 'full_name'],
        ['original_field' => 'email', 'custom_name' => 'contact_email'],
    ],
    'timeout' => 30,
    'retry_attempts' => 3,
    'retry_delay' => 60,
]);

// Dispatch webhook for a lead
ProcessWebhookSubmission::dispatch($lead);
```

### Phone Number Formatting

[](#phone-number-formatting)

```
use Skaisser\LaravelLead\Services\PhoneFormatter;

$formatter = app(PhoneFormatter::class);

// Format a phone number
$formatted = $formatter->format('11999999999', '+55'); // (11) 99999-9999

// Validate a phone number
$isValid = $formatter->isValid('1234567890', '+1');

// Get international format
$international = $formatter->toInternational('11999999999', '+55'); // +55 11 999999999

// Add custom format for a country
$formatter->addCustomFormat('33', function($numbers) {
    // Custom French formatting
    return preg_replace('/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', '$1 $2 $3 $4 $5', $numbers);
});
```

JavaScript Integration
----------------------

[](#javascript-integration)

Publish the JavaScript assets:

```
php artisan vendor:publish --tag=lead-persistence-assets
```

Include the script in your layout:

```

window.LEAD_PERSISTENCE_COOKIE_NAME = 'my_lead_id';
window.LEAD_PERSISTENCE_COOKIE_DAYS = 365;
window.LEAD_PERSISTENCE_SECURE = true;

```

### JavaScript API

[](#javascript-api)

```
// Store lead ID
window.leadStorage.storeLead('encrypted_lead_id_here');

// Get stored lead ID
const leadId = window.leadStorage.getStoredLeadId();

// Clear stored lead
window.leadStorage.clearStoredLead();

// Sync storage across layers
window.leadStorage.syncStorage();
```

### Livewire Integration

[](#livewire-integration)

The package automatically integrates with Livewire if available:

```
// In your Livewire component
$this->dispatch('store-lead', ['leadId' => $encryptedLeadId]);
$this->dispatch('check-local-storage');
$this->dispatch('clear-lead');
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Lead Model

[](#custom-lead-model)

Create your lead model and configure it:

```
// app/Models/Lead.php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Lead extends Model
{
    protected $fillable = [
        'name', 'email', 'phone', 'company',
        'country_code', 'query_data', 'accepted_terms'
    ];

    protected $casts = [
        'query_data' => 'array',
        'accepted_terms' => 'boolean',
    ];
}
```

Update the configuration:

```
// config/lead-persistence.php
'lead_model' => App\Models\Lead::class,
```

### Custom Webhook Model

[](#custom-webhook-model)

Extend the base webhook model for custom functionality:

```
namespace App\Models;

use Skaisser\LaravelLead\Models\Webhook as BaseWebhook;

class CustomWebhook extends BaseWebhook
{
    public function getAvailableFields(): array
    {
        return array_merge(parent::getAvailableFields(), [
            'custom_field' => 'Custom Field',
            'another_field' => 'Another Field',
        ]);
    }
}
```

### Webhook Transformations

[](#webhook-transformations)

Add custom transformations for webhook data:

```
// config/lead-persistence.php
'webhook_transformations' => [
    'phone' => function($value) {
        return '+1' . preg_replace('/[^0-9]/', '', $value);
    },
    'created_at' => function($value) {
        return Carbon::parse($value)->toIso8601String();
    },
],
```

Testing
-------

[](#testing)

Run the package tests:

```
composer test
```

Security
--------

[](#security)

- All lead IDs are encrypted by default using Laravel's encryption
- Visitor-isolated caching prevents data leakage between users
- Cookie security follows Laravel's session configuration
- Webhook URLs are validated before requests

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance53

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

322d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.2.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0bf71a52e0741cbfe669f9cd4d1b967e34f1b38179b44fb6032f92e5d0dfce5?d=identicon)[skaisser](/maintainers/skaisser)

---

Top Contributors

[![skaisser](https://avatars.githubusercontent.com/u/1593505?v=4)](https://github.com/skaisser "skaisser (4 commits)")

---

Tags

laravelpersistencecachewebhookcrmlead

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/skaisser-laravel-lead/health.svg)

```
[![Health](https://phpackages.com/badges/skaisser-laravel-lead/health.svg)](https://phpackages.com/packages/skaisser-laravel-lead)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[genealabs/laravel-model-caching

Automatic caching for Eloquent models.

2.4k4.8M26](/packages/genealabs-laravel-model-caching)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[mikebronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k127.1k1](/packages/mikebronner-laravel-model-caching)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
