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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,29 @@
1
1
# Release Notes
2
2
3
+
## v1.2.0 `2025-06-17`
4
+
5
+
### Added
6
+
7
+
- Introduced `ShouldSyncToCrmOnSave` to automatically initiate CRM sync after model save.
8
+
9
+
### Changed
10
+
11
+
- Renamed `CrmTrait` to `HasCrmSync` in `namespace Wazza\SyncModelToCrm\Traits;`.
12
+
- Renamed `CrmController` to `CrmSyncController` in `namespace Wazza\SyncModelToCrm\Http\Controllers;`.
13
+
- Enhanced inline documentation in both trait files to better explain their use cases.
14
+
- Updated code to use the singleton instance for CRM sync instead of creating new instances. e.g. `app(CrmSyncController::class)` instead of `new CrmSyncController()`
15
+
16
+
### Important changes from v1.1.0
17
+
- Bulk update `CrmTrait` to `HasCrmSync` for all `Wazza\SyncModelToCrm\Traits\HasCrmSync` used files.
18
+
3
19
## v1.1.0 `2025-06-04`
4
20
5
21
### Stable Release 🚀
6
22
7
23
Our first stable release. The package has been in beta for a few months without any major issues. We will keep on improving the codebase and continue to add more sync functionality.
8
24
9
25
- Added the ability for the `smtc_external_key_lookup` mapping table to support both `uuid` and `int` foreign keys.
10
-
- Fixed a bug in the `crmTrait` file where the Model instance was not given but the Model name (string).
26
+
- Fixed a bug in the `HasCrmSync` file where the Model instance was not given but the Model name (string).
Copy file name to clipboardExpand all lines: README.md
+49-94Lines changed: 49 additions & 94 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,15 +77,15 @@ use Laravel\Sanctum\HasApiTokens;
77
77
use App\Models\Entity;
78
78
use Illuminate\Database\Eloquent\SoftDeletes;
79
79
use Wazza\SyncModelToCrm\Http\Controllers\CrmProviders\HubSpotController;
80
-
use Wazza\SyncModelToCrm\Traits\crmTrait;
80
+
use Wazza\SyncModelToCrm\Traits\HasCrmSync;
81
81
82
82
class User extends Authenticatable
83
83
{
84
84
use HasApiTokens, HasFactory, Notifiable, SoftDeletes;
85
85
86
86
// include this if you wish to use the `Mutators function` or
87
87
// $this->syncToCrm() directly as appose to the observer method
88
-
use crmTrait;
88
+
use HasCrmSync;
89
89
90
90
/**
91
91
* The attributes that are mass assignable.
@@ -277,115 +277,69 @@ class User extends Authenticatable
277
277
278
278
You can trigger a model sync in several ways:
279
279
280
-
1.**Directly in a Controller:**
280
+
1.**Using the ShouldSyncToCrmOnSave (Automatic Sync on Save):**
281
+
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.
281
282
282
283
```php
283
-
(new CrmController())->setModel($user)->execute();
284
+
use Wazza\SyncModelToCrm\Traits\ShouldSyncToCrmOnSave;
285
+
286
+
class User extends Authenticatable
287
+
{
288
+
use ShouldSyncToCrmOnSave;
289
+
// ...
290
+
}
284
291
```
285
292
286
-
2. **Using the Trait in a Mutator:**
287
-
Call `$this->syncToCrm()` within your model.
293
+
**When to use:**
294
+
- Use `ShouldSyncToCrmOnSave` if you want your model to always sync to the CRM automatically after every save (create/update), with no extra code required.
295
+
- This is ideal for most use cases where you want seamless, automatic syncing.
288
296
289
-
3. **Via an Observer:**
290
-
Register an observer to automatically sync after save, update, delete, or restore events.
297
+
2. **Using the HasCrmSync (Manual or Custom Sync):**
298
+
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.
291
299
292
300
```php
293
-
namespace App\Observers;
301
+
use Wazza\SyncModelToCrm\Traits\HasCrmSync;
294
302
295
-
use App\Models\User;
296
-
use Wazza\SyncModelToCrm\Http\Controllers\CrmController;
297
-
use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit;
303
+
class User extends Authenticatable
304
+
{
305
+
use HasCrmSync;
306
+
// ...
307
+
}
298
308
299
-
class UserObserver implements ShouldHandleEventsAfterCommit
309
+
public function save(array $options = [])
300
310
{
301
-
/**
302
-
* Handle the User "created" event.
303
-
*/
304
-
public function created(User $user): void
305
-
{
306
-
echo ('create...');
307
-
(new CrmController())
308
-
->setModel($user)
309
-
->setAttemptCreate()
310
-
->execute(true);
311
-
echo ('created...');
312
-
}
313
-
314
-
/**
315
-
* Handle the User "updated" event.
316
-
*/
317
-
public function updated(User $user): void
318
-
{
319
-
echo ('update...');
320
-
(new CrmController())
321
-
->setModel($user)
322
-
->setAttemptUpdate()
323
-
->execute(true);
324
-
echo ('updated...');
325
-
}
326
-
327
-
/**
328
-
* Handle the User "deleted" event.
329
-
* Run when a user is soft-deleted.
330
-
*/
331
-
public function deleted(User $user)
332
-
{
333
-
echo ('delete...');
334
-
(new CrmController())
335
-
->setModel($user)
336
-
->setAttemptDelete()
337
-
->execute();
338
-
echo ('deleted...');
339
-
}
340
-
341
-
/**
342
-
* Handle the User "restored" event.
343
-
* Soft-delete has been reversed.
344
-
*/
345
-
public function restored(User $user): void
346
-
{
347
-
echo ('restore...');
348
-
(new CrmController())
349
-
->setModel($user)
350
-
->setAttemptRestore()
351
-
->execute();
352
-
echo ('restored...');
353
-
}
354
-
355
-
/**
356
-
* Handle the User "force deleted" event.
357
-
*/
358
-
public function forceDeleted(User $user): void
359
-
{
360
-
echo ('forceDeleted...');
361
-
}
362
-
363
-
/**
364
-
* Handle the User "saved" event.
365
-
*
366
-
*/
367
-
public function saved(User $user): void
368
-
{
369
-
// echo ('saving...');
370
-
// (new CrmController())
371
-
// ->setModel($user)
372
-
// ->setAttemptAll() // open for anything...
373
-
// ->execute(true);
374
-
// echo ('saved...');
375
-
}
311
+
parent::save($options);
312
+
$this->syncToCrmPatch(); // Manually trigger sync after save
376
313
}
377
314
```
378
315
379
-
Register the observer in your `AppServiceProvider`:
316
+
**When to use:**
317
+
- 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).
318
+
- This is ideal for advanced use cases or when you want more granular control over syncing.
319
+
320
+
3. **Directly in a Controller:**
380
321
381
322
```php
382
-
public function boot(): void
323
+
// If CrmSyncController is registered as a singleton in the service container,
324
+
// you should resolve it via dependency injection or the app() helper
0 commit comments