From 5bfe6974975114f8ce64e0d8c5ea94f7f48c53ac Mon Sep 17 00:00:00 2001 From: Gerardo Ibarra Date: Sat, 14 Oct 2023 13:52:23 -0300 Subject: [PATCH] implement morph relations --- src/ServiceProvider.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 8497432..4cb5d11 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -54,6 +54,18 @@ protected function macros() : void Blueprint::macro('foreignSnowflakeFor', function($model, $column = null) { return $this->foreignSnowflake($column ?: (new $model())->getForeignKey()); }); + + Blueprint::macro('snowflakeMorphs', function ($name, $indexName = null) { + $this->string("{$name}_type"); + $this->unsignedBigInteger("{$name}_id"); + $this->index(["{$name}_type", "{$name}_id"], $indexName); + }); + + Blueprint::macro('nullableSnowflakeMorphs', function ($name, $indexName = null) { + $this->string("{$name}_type")->nullable(); + $this->unsignedBigInteger("{$name}_id")->nullable(); + $this->index(["{$name}_type", "{$name}_id"], $indexName); + }); } /**