From d5829a198e61effa8ef3d726dcf873803fc5745b Mon Sep 17 00:00:00 2001 From: Railken Date: Sat, 6 Apr 2024 14:34:58 +0200 Subject: [PATCH] add Yaml and add custom column type --- .../amethyst.attribute-schema.resolvers.php | 1 + src/AttributeSchemaResolvers/YamlResolver.php | 20 +++++++++++++++++++ src/Observers/AttributeSchemaObserver.php | 3 ++- tests/Managers/AttributeSchemaYamlTest.php | 15 ++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/AttributeSchemaResolvers/YamlResolver.php create mode 100644 tests/Managers/AttributeSchemaYamlTest.php diff --git a/config/amethyst.attribute-schema.resolvers.php b/config/amethyst.attribute-schema.resolvers.php index d3a5c77..b31d465 100644 --- a/config/amethyst.attribute-schema.resolvers.php +++ b/config/amethyst.attribute-schema.resolvers.php @@ -12,4 +12,5 @@ 'DateTime' => Amethyst\AttributeSchemaResolvers\DateTimeResolver::class, 'DataName' => Amethyst\AttributeSchemaResolvers\DataNameResolver::class, 'MorphTo' => Amethyst\AttributeSchemaResolvers\MorphToResolver::class, + 'Yaml' => Amethyst\AttributeSchemaResolvers\YamlResolver::class, ]; diff --git a/src/AttributeSchemaResolvers/YamlResolver.php b/src/AttributeSchemaResolvers/YamlResolver.php new file mode 100644 index 0000000..60b9ba7 --- /dev/null +++ b/src/AttributeSchemaResolvers/YamlResolver.php @@ -0,0 +1,20 @@ +newEntity()->getTable(), function (Blueprint $table) use ($attributeSchema, $onChange, $options) { - $method = $this->getMethod($attributeSchema); + + $method = !empty($options->column) ? $options->column : $this->getMethod($attributeSchema); $arguments = $attributeSchema->getResolver()->getDatabaseArguments(); diff --git a/tests/Managers/AttributeSchemaYamlTest.php b/tests/Managers/AttributeSchemaYamlTest.php new file mode 100644 index 0000000..9b30d77 --- /dev/null +++ b/tests/Managers/AttributeSchemaYamlTest.php @@ -0,0 +1,15 @@ +resetFields(); + + $this->commonField('yaml', 'Yaml', ["valid:yaml"]); + + $this->resetFields(); + } +}