You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A library that will syncronise any defined database table properties (inside the Model) to an external Crm provider, like [HubSpot](https://www.hubspot.com/), [Pipedrive](https://www.pipedrive.com/en) and more.
10
10
@@ -15,16 +15,22 @@ The idea around this library is to make it very easy for a developer to define i
15
15
After each first time successful sync, the CRM Object primary key will be stored in a mapping table against the local table primary key. This allows for quicker loading times for future changes.
16
16
17
17
Update your Model with 4 properties that define the rules for 3rd-party CRM synchronization:
1. the `User` Model will syncronize to both the `Sandbox` and `Production`**HubSpot** environments _($syncModelCrmEnvironment)_.
25
28
2. It will only syncronize the `name` and `email` properties to the HubSpot corresponding `firstname` and `email` fields _($syncModelCrmPropertyMapping)_.
26
29
3. When there is no internal mapping yet stored, the CRM record will be uniquely loaded using the `email` property _($syncModelCrmUniqueSearch)_.
27
30
4. In order for the script to know which remote CRM object relates to the User model, `contact`_($syncModelCrmRelatedObject)_ have to be defined as the remote item.
31
+
5. The _($syncModelCrmDeleteRules)_ property is used to instruct the Crm what action to take when a local record is deleted/removed. For example, when _SoftDeletes_ are enabled locally, the crm will use the `soft_delete` rules to update the crm records or alternatively Archive the record in the crm.
32
+
6. The reverse to the above, _($syncModelCrmActiveRules)_ will be used to define the action that will be taken when deleted records are activated again.
33
+
7. Finally, the non-required _($syncModelCrmAssociateRules)_ property is used to define the relationship (associations) between objects. e.g. `user` to `entity`.
28
34
29
35
```PHP
30
36
class User extends Authenticatable
@@ -48,6 +54,7 @@ class User extends Authenticatable
48
54
49
55
/**
50
56
* Mapping array for local and CRM properties
57
+
* This will be the primary property used to cycle through the crm providers
51
58
*
52
59
* @var array
53
60
*/
@@ -72,10 +79,65 @@ class User extends Authenticatable
72
79
/**
73
80
* The CRM object to sync this model to.
74
81
* This is the CRM object type (e.g. contact, company, deal, etc.)
82
+
* If this is null or not provided, the `object_table_mapping` key will be used from the config file.
75
83
*
76
84
* @var string
77
85
*/
78
86
public $syncModelCrmRelatedObject = 'contact';
87
+
88
+
/**
89
+
* The Crm Delete rules to follow.
90
+
* i.e. if Soft-delete is applicable, what should the CRM record be updated to?
91
+
* if Hard-delete is used, the record will be deleted/archived in the CRM.
92
+
*
93
+
* @var array
94
+
*/
95
+
public $syncModelCrmDeleteRules = [
96
+
'hard_delete' => [
97
+
'hubspot' => false,
98
+
],
99
+
'soft_delete' => [
100
+
'hubspot' => [
101
+
'lifecyclestage' => 'other',
102
+
'hs_lead_status' => 'DELETED',
103
+
],
104
+
]
105
+
];
106
+
107
+
/**
108
+
* The Crm Active/Restore rules to follow.
109
+
* These will be the rules to follow for any new entries that are not soft-deleted.
110
+
*/
111
+
public $syncModelCrmActiveRules = [
112
+
'hubspot' => [
113
+
'lifecyclestage' => 'customer',
114
+
'hs_lead_status' => 'OPEN',
115
+
],
116
+
];
117
+
118
+
/**
119
+
* The Crm Associations to sync.
120
+
* This is used to associate the model with other CRM objects.
(new CrmController())->setModel($user)->execute(CrmController::EXEC_ACTION_DELETE);
184
+
echo ('deleted...');
185
+
}
186
+
187
+
/**
188
+
* Handle the User "restored" event.
189
+
* Soft-delete has been reversed.
190
+
*/
191
+
public function restored(User $user): void
192
+
{
193
+
echo ('restore...');
194
+
(new CrmController())->setModel($user)->execute(CrmController::EXEC_ACTION_RESTORE);
195
+
echo ('restored...');
196
+
}
197
+
198
+
/**
199
+
* Handle the User "force deleted" event.
200
+
*/
201
+
public function forceDeleted(User $user): void
202
+
{
203
+
echo ('forceDeleted...');
204
+
}
205
+
206
+
/**
207
+
* Handle the User "saved" event.
208
+
*
209
+
*/
210
+
public function saved(User $user): void
211
+
{
212
+
echo ('saving...');
213
+
}
99
214
}
100
215
```
101
216
3. Inside an event job. This is a good method to separate the logic from the save event and put the sync in a job queue to be processed shortly after the record has been saved.
0 commit comments