Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created June 29, 2022 14:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ziadoz/980044b03fcab2a9c8164289881d2bdf to your computer and use it in GitHub Desktop.
Laravel - JSON Polymorphic Columns
<?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