Download the PHP package wazza/sync-model-to-crm without Composer
On this page you can find all versions of the php package wazza/sync-model-to-crm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sync-model-to-crm
Sync Model to CRM
Easily synchronize your Laravel Eloquent models with remote CRM providers such as HubSpot, Pipedrive, and more. This package allows you to define which model properties and relationships should be kept in sync with external CRM objects, providing a seamless integration experience.
Features
- Flexible Property Mapping: Define which model attributes map to CRM fields.
- Multi-Environment Support: Sync to multiple CRM environments (e.g., sandbox, production).
- Relationship Sync: Automatically associate related models (e.g., User to Company).
- Customizable Sync Triggers: Initiate syncs via observers, mutators, or queued jobs.
- Extensible: Easily add support for additional CRM providers.
Supported CRMs
- HubSpot
- Sync
User
model to HubSpotContact
object. - Sync
Entity
model to HubSpotCompany
object. - Manage associations between
Contact
andCompany
. - (Coming soon) Support for
Deal
andTicket
objects.
- Sync
- Planned Support
- Pipedrive
- Salesforce
- Zoho CRM
- Others
Requirements
- PHP: 8.2 or higher
- Laravel: 12.x
How It Works
Define a set of properties on your Eloquent models to control how and when they sync with your CRM provider. After the first successful sync, the CRM object’s primary key is stored in a mapping table for efficient future updates.
Required Model Properties
Add the following properties to your model to enable CRM synchronization:
Property | Type | Description |
---|---|---|
$syncModelCrmEnvironment |
string/array/null | CRM environments to sync with (e.g., ['sandbox', 'production'] ). Defaults to config value. |
$syncModelCrmPropertyMapping |
array (required) | Maps local model attributes to CRM fields. |
$syncModelCrmUniqueSearch |
array (required) | Defines unique fields for identifying CRM records. |
$syncModelCrmRelatedObject |
string | CRM object type (e.g., contact ). Defaults to config mapping. |
$syncModelCrmDeleteRules |
array (required) | Rules for handling deletes (soft/hard) in the CRM. |
$syncModelCrmActiveRules |
array (required) | Rules for restoring/reactivating records in the CRM. |
$syncModelCrmAssociateRules |
array (optional) | Defines associations with other CRM objects. |
Example: User Model
Below is a sample User
model configured for CRM synchronization:
Usage
You can trigger a model sync in several ways:
-
Using the ShouldSyncToCrmOnSave (Automatic Sync on Save): Add the
ShouldSyncToCrmOnSave
to your Eloquent model to automatically trigger a CRM sync every time the model is saved (created or updated). This is the easiest way to ensure your model stays in sync with your CRM provider without writing custom logic.When to use:
- Use
ShouldSyncToCrmOnSave
if you want your model to always sync to the CRM automatically after every save (create/update), with no extra code required. - This is ideal for most use cases where you want seamless, automatic syncing.
- Use
-
Using the HasCrmSync (Manual or Custom Sync): Add the
HasCrmSync
to your model if you want to control exactly when the sync happens. This trait provides methods like$this->syncToCrm()
,$this->syncToCrmCreate()
,$this->syncToCrmUpdate()
, etc., which you can call from mutators, custom methods, or anywhere in your application.When to use:
- Use
HasCrmSync
if you want to trigger syncs only at specific times, or if you need to customize the sync logic (e.g., only sync on certain conditions, or from a controller, observer, or job). - This is ideal for advanced use cases or when you want more granular control over syncing.
- Use
-
Directly in a Controller:
Note: Instantiating with
new CrmSyncController()
will always create a new instance, bypassing the singleton. To use the singleton, always resolve it from the container. -
Via an Observer: Register an observer to automatically sync after save, update, delete, or restore events.
- In a Job: Offload sync logic to a queued job for asynchronous processing.
Installation
-
Install via Composer:
-
Register the Service Provider (if not auto-discovered): Add to
bootstrap/providers.php
:If your package supports Laravel auto-discovery, this step may be optional.
-
Publish Config and Migrations:
-
Configure Environment Variables: Add the following to your
.env
file (seeconfig/sync_modeltocrm.php
for details): -
Cache Config:
- Review Configuration: Adjust the published config file as needed. You also do not need all of the env settings above, have a look at the config file and overwrite any applicable items. Happy coding 😉
Monitoring & Logs
Set your desired log level in the config file (1
= high, 3
= low verbosity).
Monitor sync activity in your Laravel log file:
Testing
We have included a few unit tests, please expand if you wish to fork and help expand the functionalities.
Example output:
More tests and features coming soon!
License
This project is open-sourced under the MIT license.
All versions of sync-model-to-crm with dependencies
guzzlehttp/guzzle Version ^7.8
hubspot/api-client Version ^10.2
illuminate/support Version ^12.0
php Version ^8.2 || ^8.3