Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create unique indexes in Laravel?

I create table with migration in laravel 5.6.

I need create a unique indexes with migration.

My code is:

$table->index([
            'system',
            'code',
            'city',
            'seat',
            'type'
        ], 'PrimaryPayment');

But after run migrate . in phpmyadmin -> table -> table_name -> indexes show unique: No

How to create unique indexes?

like image 981
mySun Avatar asked Mar 06 '18 09:03

mySun


1 Answers

You can use unique() method on migration:

$table->string('email')->unique();

Or like this for compound unique index:

$table->unique([
        'system',
        'code',
        'city',
        'seat',
        'type'
    ], 'PrimaryPayment');
like image 124
Sohel0415 Avatar answered Nov 12 '22 02:11

Sohel0415