whilesmart/eloquent-leads

Polymorphic lead register with a status lifecycle and DB-level dedupe for Laravel applications.

Maintainers

Package info

github.com/whilesmartphp/eloquent-leads

pkg:composer/whilesmart/eloquent-leads

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-dev 2026-07-12 17:35 UTC

This package is auto-updated.

Last update: 2026-07-12 17:55:46 UTC


README

A polymorphic lead register for Laravel: a discovered potential customer with a status lifecycle. A lead is not a customer and never auto-converts; converting one into a customer is the host app's concern. Each lead is scoped to an owner (a workspace, organization, user) through whilesmart/eloquent-owner-access, can point at a polymorphic subject it is interested in (e.g. a product), and is deduplicated per owner at the database level.

Install

composer require whilesmart/eloquent-leads
php artisan migrate

Routes register automatically under the api prefix with auth:sanctum. Set LEADS_REGISTER_ROUTES=false to mount them yourself.

Owning model

Add the trait to whatever owns leads:

use Whilesmart\Leads\Traits\HasLeads;

class Workspace extends Model
{
    use HasLeads;
}

$workspace->leads()->create([
    'name' => 'Jane Doe',
    'channel' => 'referral',
    'source' => 'Acme Inc',
    'source_url' => 'https://acme.example/contact/jane',
    'contact_email' => 'jane@acme.example',
    'why' => 'Asked about the enterprise plan',
]);

Deduplication

A lead's dedupe_hash is a per-owner fingerprint of its strongest identity, in order: source_url, then handle, then contact_email, then contact_phone. Two leads for the same owner that share that identity produce the same hash, and a unique index on dedupe_hash lets the database reject the duplicate. A lead with no identifying value has a null hash and is never treated as a duplicate.

Endpoints

Method Path Purpose
GET /api/leads List (filter by status)
POST /api/leads Create
GET /api/leads/{lead} Show
PUT/PATCH /api/leads/{lead} Update
DELETE /api/leads/{lead} Soft delete
PATCH /api/leads/{lead}/status Move through the lifecycle

Status

LeadStatus: new, qualified, contacted, won, lost, dismissed. status is stored as a string and validated against the enum on write.