Skip to content
Customer Handling Library for Laravel
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Konekt Customer Library (Laravel)

Travis Build Status Packagist version Packagist downloads StyleCI MIT Software License

This is a Concord module for handling customers.

Designed to:

  • Be very much Laravel common-sense;
  • Only does the basic shit;
  • Lets you to customize the hell out of it.


composer require konekt/customer

With Concord

The service provider should be wired via Concord.

Add the customer module to `config/concord.php:

return [
    'modules' => [
        Konekt\Customer\Providers\ModuleServiceProvider::class => []
        // other modules if necessary

If there's no concord.php config file use this command:

php artisan vendor:publish --provider="Konekt\Concord\ConcordServiceProvider" --tag=config

Run Migrations

php artisan migrate

Without Concord

OK, ok. You might be freaked out of this Concord thing. Then you can omit registering the service provider, but then the migrations won't be published, so copy them from src/resorces/database/migrations/ to your app's migration folder.


Creating Customers

Just go the plain old Laravel way:

use Konekt\Customer\Models\Customer;
use Konekt\Customer\Models\CustomerType;

$johnDoe = Customer::create([
    'firstname' => 'John',
    'lastname'  => 'Doe',
    'type'      => CustomerType::INDIVIDUAL

echo $johnDoe->getName();
// John Doe
// bool(true)
// bool(false)

$acmeInc = Customer::create([
   'company_name' => 'Acme Inc.',
   'type'      => CustomerType::ORGANIZATION

echo $acmeInc->getName();
// Acme Inc.
// bool(false)
// bool(true)


Name Type Notes
id autoinc
type CustomerType enum
email string
phone string(22)
firstname string
lastname string
company_name string
tax_nr string(17) Tax/VAT Identification Number
registration_nr Company/Trade Registration Number
is_active bool true by default
last_purchase_at DateTime nullable



Const Value Notes
ORGANIZATION organization (default) Use for companies, foundations, GOs, NGOs, etc
INDIVIDUAL individual For natural human customers

Extending, Customizing

With Concord

Everything is already written in Concord docs at the Models and the Enums sections, so read that first if you haven't done that yet.

Extending CustomerType

This is an enum type so if you want to add further variants, extend the class and define new consts:

// App\CustomerType.php
class CustomerType extends Konekt\Customer\Models\CustomerType
    const ROBOT = 'robot';
    const ALIEN = 'alien';
    // You can also change the default value:
    const __default = self::ROBOT;

You need to register your type so that it will be used instead of the stock CustomerType:

// app/Providers/AppServiceProvider.php:

use Illuminate\Support\ServiceProvider;
use Konekt\Customer\Contracts\CustomerType as CustomerTypeContract;

class AppServiceProvider extends ServiceProvider
    public function boot()
            CustomerTypeContract::class, \App\CustomerType::class

So now your extended type is in effect:

use Konekt\Customer\Models\Customer;

$robot = Customer::create([
    'firstname' => 'R2D2'

// object(App\CustomerType)#1050 (1) {
//     ["value":protected]=>
//     string(5) "robot"
//   }

Extending Customer

First create your extended model class

// app/Customer.php
class Customer extends Konekt\Customer\Models\Customer
    public function getName()
        if ($this->type->isRobot()) {
            return 'Robot ' . $this->firstname;
        return parent::getName();        

Register the model with concord:

// app/Providers/AppServiceProvider.php:

use Illuminate\Support\ServiceProvider;
use Konekt\Customer\Contracts\Customer as CustomerContract;

class AppServiceProvider extends ServiceProvider
    public function boot()
            CustomerContract::class, \App\Customer::class

So now any other library using the Konekt Customer module will be aware of your new type and it will be used.

use Konekt\Customer\Models\CustomerProxy;

echo CustomerProxy::modelClass();
// App\Customer

$r2d2 = CustomerProxy::create([
    'firstname' => 'R2D2'
//=> App\Customer {#1062
//       updated_at: "2017-11-26 14:48:48",
//       created_at: "2017-11-26 14:48:48",
//       id: 8,
//       type: "robot",
//       firstname: "R2D2",
//     }

echo $r2d2->getName();
// 'Robot R2D2'

Without Concord

If you're not using Concord and no other module/library depends on this module, just extend Customer with plain OOP and you're good to go.

Regarding to the automatic enum mapping refer to the enum-eloquent readme

Runnig Tests

In Console

vendor/bin/phpunit -c phpunit.xml

Configure PhpStorm

  1. Go to settings -> PHP -> Testing frameworks
  2. Add PHPUnit local
  3. Choose composer autoloader (need to install deps in advance with composer install)
  4. Point "path to script" to vendor/autoload.php (full path)
  5. Choose default configuration file: phpunit.xml
You can’t perform that action at this time.