CarlosCarucce CarlosCarucce - 2 years ago 125
PHP Question

How to create unique constraints in laravel 5.2?

How do I create unique constraints using laravel 5.2 Schema Builder?

Schema::create('my_pivot', function(Blueprint $table){



//Here i need to add an unique constraint to 'key1' + 'key2'


Answer Source

You can pass an array to the unique method.

$table->unique(['key1', 'key2']);

Documented under Available Index Types in the manual

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download