From 7cdc4ddabe12b774accdda251b98dad50856f207 Mon Sep 17 00:00:00 2001 From: Abner Tudtud Date: Mon, 21 Oct 2024 09:56:44 +0800 Subject: [PATCH 1/2] Sync attribute when creating or updating --- src/Models/Laravel/Attribute.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Models/Laravel/Attribute.php b/src/Models/Laravel/Attribute.php index d7a3262e..d9dc600e 100644 --- a/src/Models/Laravel/Attribute.php +++ b/src/Models/Laravel/Attribute.php @@ -3,6 +3,7 @@ namespace Enjin\Platform\Models\Laravel; use Enjin\Platform\Database\Factories\AttributeFactory; +use Enjin\Platform\Jobs\SyncMetadata; use Enjin\Platform\Models\BaseModel; use Enjin\Platform\Models\Laravel\Traits\Attribute as AttributeMethods; use Enjin\Platform\Models\Laravel\Traits\EagerLoadSelectFields; @@ -82,4 +83,21 @@ protected static function newFactory(): AttributeFactory { return AttributeFactory::new(); } + + public static function boot(): void + { + parent::boot(); + + static::created(function($model) { + if ($model->key == '0x757269') { + SyncMetadata::dispatch($model->id); + } + }); + + static::updated(function($model) { + if ($model->key == '0x757269') { + SyncMetadata::dispatch($model->id); + } + }); + } } From 75496397814d4afe26c1821e5884bb377a738bf7 Mon Sep 17 00:00:00 2001 From: Abner Tudtud Date: Mon, 21 Oct 2024 10:00:11 +0800 Subject: [PATCH 2/2] lint --- src/Models/Laravel/Attribute.php | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Models/Laravel/Attribute.php b/src/Models/Laravel/Attribute.php index d9dc600e..cb6eda00 100644 --- a/src/Models/Laravel/Attribute.php +++ b/src/Models/Laravel/Attribute.php @@ -39,6 +39,23 @@ class Attribute extends BaseModel */ protected $guarded = []; + public static function boot(): void + { + parent::boot(); + + static::created(function ($model): void { + if ($model->key == '0x757269') { + SyncMetadata::dispatch($model->id); + } + }); + + static::updated(function ($model): void { + if ($model->key == '0x757269') { + SyncMetadata::dispatch($model->id); + } + }); + } + /** * The attribute key as String. */ @@ -83,21 +100,4 @@ protected static function newFactory(): AttributeFactory { return AttributeFactory::new(); } - - public static function boot(): void - { - parent::boot(); - - static::created(function($model) { - if ($model->key == '0x757269') { - SyncMetadata::dispatch($model->id); - } - }); - - static::updated(function($model) { - if ($model->key == '0x757269') { - SyncMetadata::dispatch($model->id); - } - }); - } }