If with postgres 14 /mysql 8 servers can I define unique index based on json field ?
With next migration :
Schema::create('quiz_categories', function (Blueprint $table) {
$table->id();
$table->json('name')->comment('This column is used for i18n support');
$table->boolean('active')->default(false);
$table->timestamps();
$table->unique(['name', 'active'], 'quiz_categories_name_active_index');
});
I got error :
Illuminate\Database\QueryException
SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type. (Connection: pgsql, SQL: alter table "quiz_categories" add constraint "quiz_categories_name_active_index" unique ("name", "active"))
?
->storedAs()to create a generated column. It is mentioned in the Laravel docs, but with no example. See example in this answer: stackoverflow.com/a/56290032/20860