A unique index ensures the index key columns do not contain any duplicate values. Unique Index can be composite (multiple).
Laravel will automatically construct an unique index name based on the table, column names, and index type (unique) when creating an index. To drop an unique index, you must first give it a name.
Create a unique index with users_email_unique name.
$table->string('email')->unique();
// or
$table->string('email');
$table->unique('email');
users_email_unique - is name of Unique Index.
$table->dropUnique('users_email_unique');
Create a composite unique index with users_name_email_unique name.
$table->unique(['email', 'name']);
users_name_email_unique - is name of Composite Unique Index.
$table->dropUnique('users_name_email_unique');
MySQL has a limit here: 64 characters for unique index name length. You may need to set the index name yourself.
// unique index
$table->unique('id', 'custom_unique_index_name');
// composite unique index
$table->unique(['id', 'parent_id'], 'custom_unique_index_name');
$table->renameIndex('users_name_email_unique', 'users_name_email_unique_custom')