From 197f16eedf6d5555d786bb0ddccc206d5b4ea359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Wed, 8 Mar 2023 10:39:16 +0100 Subject: [PATCH] rename metas to metaData --- ...01_000000_create_root_meta_data_table.php} | 4 +-- src/Models/Meta.php | 26 +------------------ src/Traits/HasMeta.php | 25 ------------------ src/Traits/HasMetaData.php | 17 ++++++++++++ tests/Models/MetaTest.php | 10 +++---- 5 files changed, 25 insertions(+), 57 deletions(-) rename database/migrations/{2020_07_01_000000_create_root_metas_table.php => 2020_07_01_000000_create_root_meta_data_table.php} (82%) delete mode 100644 src/Traits/HasMeta.php create mode 100644 src/Traits/HasMetaData.php diff --git a/database/migrations/2020_07_01_000000_create_root_metas_table.php b/database/migrations/2020_07_01_000000_create_root_meta_data_table.php similarity index 82% rename from database/migrations/2020_07_01_000000_create_root_metas_table.php rename to database/migrations/2020_07_01_000000_create_root_meta_data_table.php index 216271b9..bbc3310a 100644 --- a/database/migrations/2020_07_01_000000_create_root_metas_table.php +++ b/database/migrations/2020_07_01_000000_create_root_meta_data_table.php @@ -11,7 +11,7 @@ */ public function up(): void { - Schema::create('root_metas', static function (Blueprint $table): void { + Schema::create('root_meta_data', static function (Blueprint $table): void { $table->id(); $table->uuidMorphs('metable'); $table->string('key')->index(); @@ -27,6 +27,6 @@ public function up(): void */ public function down(): void { - Schema::dropIfExists('root_metas'); + Schema::dropIfExists('root_meta_data'); } }; diff --git a/src/Models/Meta.php b/src/Models/Meta.php index 78a37e24..3e73e024 100644 --- a/src/Models/Meta.php +++ b/src/Models/Meta.php @@ -39,7 +39,7 @@ class Meta extends Model implements Contract * * @var string */ - protected $table = 'root_metas'; + protected $table = 'root_meta_data'; /** * Get the proxied interface. @@ -64,28 +64,4 @@ public function metable(): MorphTo { return $this->morphTo(); } - - /** - * Get the casts array. - */ - public function getCasts(): array - { - $casts = parent::getCasts(); - - if (! isset($this->attributes['key']) - || ! isset($this->attributes['metable_type']) - || ! class_exists($this->attributes['metable_type'])) { - return $casts; - } - - $model = new ($this->attributes['metable_type'])(); - - if (! method_exists($model, 'getMetaCasts')) { - return $casts; - } - - return array_merge($casts, array_filter([ - 'value' => $model->getMetaCasts()[$this->attributes['key']] ?? null, - ])); - } } diff --git a/src/Traits/HasMeta.php b/src/Traits/HasMeta.php deleted file mode 100644 index ae383d98..00000000 --- a/src/Traits/HasMeta.php +++ /dev/null @@ -1,25 +0,0 @@ -morphMany(Meta::getProxiedClass(), 'metable'); - } - - /** - * Get the casts for the meta values. - */ - public function getMetaCasts(): array - { - return []; - } -} diff --git a/src/Traits/HasMetaData.php b/src/Traits/HasMetaData.php new file mode 100644 index 00000000..119bf7c0 --- /dev/null +++ b/src/Traits/HasMetaData.php @@ -0,0 +1,17 @@ +morphMany(Meta::getProxiedClass(), 'metable'); + } +} diff --git a/tests/Models/MetaTest.php b/tests/Models/MetaTest.php index e3879df5..fe096e08 100644 --- a/tests/Models/MetaTest.php +++ b/tests/Models/MetaTest.php @@ -5,7 +5,7 @@ use Cone\Root\Models\Medium; use Cone\Root\Models\Meta; use Cone\Root\Tests\TestCase; -use Cone\Root\Traits\HasMeta; +use Cone\Root\Traits\HasMetaData; class MetaTest extends TestCase { @@ -17,7 +17,7 @@ public function setUp(): void $this->model = new class(Medium::factory()->make()->toArray()) extends Medium { - use HasMeta; + use HasMetaData; }; $this->model->save(); @@ -34,12 +34,12 @@ public function a_meta_belongs_to_a_metable() } /** @test */ - public function a_metable_model_has_metas() + public function a_metable_model_has_meta_data() { - $this->model->metas()->save( + $this->model->metaData()->save( $meta = Meta::factory()->make() ); - $this->assertTrue($this->model->metas->first()->is($meta)); + $this->assertTrue($this->model->metaData->first()->is($meta)); } }