›
byrcsc/laravel-customer-health · 1.x
Install the package, publish its assets, and prepare an Eloquent model for tracking.
Use this setup when an application is ready to store customer health data in its own database.
Laravel Customer Health requires PHP 8.3 or later and Laravel 12 or 13.
composer require byrcsc/laravel-customer-healthLaravel discovers CustomerHealthServiceProvider automatically.
php artisan vendor:publish --tag="customer-health-config"This creates config/customer-health.php. The default configuration writes
inline to the application's default database connection and keeps raw events
forever.
Configure table names and database connections before running the migrations. Changing either after data exists requires an application migration.
php artisan vendor:publish --tag="customer-health-migrations"
php artisan migrateThe published migrations create four tables:
| Table | Purpose |
|---|---|
customer_health_events | Append-only raw product activity |
customer_health_milestones | Permanent first occurrences and onboarding completion |
customer_health_scores | Append-only score history and signal breakdowns |
customer_health_summaries | One current row per tenant, subject, and score |
All four table names are configurable under table_names.
The customer, account, team, workspace, or other model whose health you measure
must implement Trackable:
namespace App\Models;
use ByRcsc\LaravelCustomerHealth\Concerns\TracksCustomerHealth;
use ByRcsc\LaravelCustomerHealth\Contracts\Trackable;
use Illuminate\Database\Eloquent\Model;
final class Team extends Model implements Trackable
{
use TracksCustomerHealth;
}TracksCustomerHealth is optional. It adds the productEvents() and
milestones() relations plus lastProductActivity() and hasAdopted()
helpers. Implementing Trackable is the requirement for facade methods.
The model must be saved before you track an event or compute a score. Integer and string model keys are supported. Polymorphic identities use Laravel's morph class, so an enforced morph map is respected.
Events, checklists, and health scores are classes registered in configuration:
use App\CustomerHealth\CustomerHealthScore;
use App\CustomerHealth\Events\TeammateInvited;
use App\CustomerHealth\Events\WorkflowCreated;
use App\CustomerHealth\Onboarding;
return [
// ...
'events' => [
WorkflowCreated::class,
TeammateInvited::class,
],
'checklists' => [
Onboarding::class,
],
'scores' => [
CustomerHealthScore::class,
],
];The package validates these declarations when their registries resolve. Missing event registration fails before an event is written.
Rebuild Laravel's configuration cache after deployment changes:
php artisan config:cacheLong-running workers must also restart before they see new event, checklist, score, connection, or queue configuration.