Maintain local ⭤ remote in sync with automatic AT Protocol parity for Laravel (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpParity\Concerns;
4
5use SocialDept\AtpParity\Publish\PublishResult;
6use SocialDept\AtpParity\Publish\PublishService;
7
8/**
9 * Trait for Eloquent models that can be manually published to AT Protocol.
10 *
11 * @mixin \Illuminate\Database\Eloquent\Model
12 */
13trait PublishesRecords
14{
15 use HasAtpRecord;
16
17 /**
18 * Publish this model to AT Protocol.
19 *
20 * If the model has a DID association (via did column or relationship),
21 * it will be used. Otherwise, use publishAs() to specify the DID.
22 */
23 public function publish(): PublishResult
24 {
25 return app(PublishService::class)->publish($this);
26 }
27
28 /**
29 * Publish this model as a specific user.
30 */
31 public function publishAs(string $did): PublishResult
32 {
33 return app(PublishService::class)->publishAs($did, $this);
34 }
35
36 /**
37 * Update the published record on AT Protocol.
38 */
39 public function republish(): PublishResult
40 {
41 return app(PublishService::class)->update($this);
42 }
43
44 /**
45 * Delete the record from AT Protocol.
46 */
47 public function unpublish(): bool
48 {
49 return app(PublishService::class)->delete($this);
50 }
51
52 /**
53 * Check if this model has been published to AT Protocol.
54 */
55 public function isPublished(): bool
56 {
57 return $this->hasAtpRecord();
58 }
59}