Created
June 29, 2022 14:52
-
-
Save ziadoz/980044b03fcab2a9c8164289881d2bdf to your computer and use it in GitHub Desktop.
Laravel - JSON Polymorphic Columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (! Schema::hasColumns('table', ['model_type', 'model_ids'])) { | |
Schema::table('table', function (Blueprint $table) { | |
$table->string('model_type'); | |
$table->json('model_ids'); | |
$table->rawIndex('((CAST(model_ids->"$[*]" AS UNSIGNED ARRAY))), model_type', 'model_ids_model_type'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment