Search by

itmosoft / laravel-customer-groups

adeelrao007

Customer segmentation and group membership management for Laravel applications.

Package info

github.com/ITMOSOFT/laravel-customer-groups

pkg:composer/itmosoft/laravel-customer-groups

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-11-16 10:56 UTC

This package is auto-updated.

Last update: 2026-11-16 10:56:49 UTC


README

Customer segmentation and group membership management for Laravel applications.

Requirements

  • PHP 8.3+
  • Laravel 12 or 13

Installation

composer require itmosoft/laravel-customer-groups
php artisan vendor:publish --tag=itmosoft-customer-groups-config
php artisan migrate

Configuration

The published config/itmosoft-customer-groups.php file contains:

return [
    'table_prefix' => 'itmosoft_',
    'customer_model' => App\Models\User::class,
];

Set customer_model to the Eloquent model representing customers in your application.

Add the customer trait

Add HasCustomerGroups to your customer model:

use ItmoSoft\CustomerGroups\Concerns\HasCustomerGroups;

class Customer extends Model
{
    use HasCustomerGroups;
}

The relationship is polymorphic, so customer models can use their own table and primary key.

Create and manage groups

use ItmoSoft\CustomerGroups\CustomerGroupManager;

$manager = app(CustomerGroupManager::class);

$vip = $manager->createGroup([
    'name' => 'VIP Customers',
    'description' => 'Customers eligible for VIP benefits',
    'metadata' => ['tier' => 'gold'],
]);

$manager->addCustomer($customer, $vip);
$manager->removeCustomer($customer, $vip);
$manager->syncCustomerGroups($customer, [$vip]);

$groups = $manager->groupsForCustomer($customer);
$isVip = $customer->belongsToCustomerGroup('vip-customers');

Groups can also be resolved by their numeric ID or slug:

$group = $manager->findGroup('vip-customers');
$activeGroups = $manager->activeGroups();

Eloquent relationships

Customer model:

$customer->customerGroups;
$customer->customerGroups()->where('is_active', true)->get();

Customer group model:

use ItmoSoft\CustomerGroups\Models\CustomerGroup;

$group = CustomerGroup::where('slug', 'vip-customers')->firstOrFail();
$group->customers;

Database tables

By default, the package creates:

  • itmosoft_customer_groups
  • itmosoft_customer_group_memberships

The membership table is polymorphic and supports multiple customer model classes. A composite unique index prevents duplicate memberships.

Changing table_prefix after migrations have run requires a corresponding database migration; do not change it casually in an existing installation.

Integration boundaries

This package owns customer groups and memberships only. It does not implement customer records, price calculation, discount application, or promotion redemption. Applications can use group membership as an input to laravel-pricing or laravel-promotions.

Testing

composer install
composer test

License

MIT.