Skip to content

Customers

Customers give a user or company a lightweight CRM — a place to track the people and companies they do business with, distinct from Reshape's own users and companies. A customer can represent either a person or a company, and can be linked to multiple owners.

A customer's detail page

Person or company

Customer (app/Models/Customer.php) doesn't store person/company fields itself — informationable points at either a CustomerCompanyInformation or a CustomerPersonInformation record via a polymorphic relation:

php
// Which kind of record this customer is...
$customer->isCompany() : bool
$customer->isPerson() : bool

Because a Customer uses the same HasContacts, HasAddresses, and HasSocials traits as User and Company, it gets contacts, addresses, and social links for free, and — via CommentableInterfacecomments too.

Ownership

A customer can belong to more than one owner (a user and a company, for instance) through a many-to-many polymorphic relation.

Trait Methods (HasCustomers)

php
// The customers owned by this user or company...
$user->customers() : Illuminate\Database\Eloquent\Relations\MorphToMany

// Determine whether this model has any customers...
$user->hasCustomers() : bool

User and Company both use HasCustomers. The pivot itself is a first-class model, Customerable, which is how a customer can be "owned by" one company while also being "visible to" another, or created by a specific user (Customer::owningCustomerable() identifies the primary owner).

Actions (app/Actions/Customers/)

php
// Create a customer (person or company information created in the same transaction)...
CreateCustomer::create(array $input) : App\Models\Customer

// Update a customer's information record...
UpdateCustomer::update(Customer $customer, array $input) : void

// Delete a customer and its information record...
DeleteCustomer::delete(Customer $customer) : void

// Attach an additional owner to a customer...
CreateCustomerable::create(Customer $customer, array $input) : App\Models\Customerable

// Update or remove an existing owner relationship...
UpdateCustomerable::update(Customerable $customerable, array $input) : void
DeleteCustomerable::delete(Customerable $customerable) : void

Customers are managed both through a polymorphic, owner-scoped API and a flat, role-gated management API, including a dedicated endpoint for managing a customer's owners (Customerable records) directly.

In the frontend

Customers are a good example to study when building your own admin-style CRUD screen — the create flow (web/src/routes/management/customers/create/) and detail view (.../$customerId/) are referenced throughout the Forms, Tables, and Panels pages as the representative real-world usage.