2016-04-25 74 views
1

如何使用laravel 5.2架構生成器創建唯一約束?如何在laravel 5.2中創建唯一約束?

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

    $table->increments('id'); 
    $table->integer('table1_id')->unsigned(); 
    $table->integer('table2_id')->unsigned(); 

    $table->foreign('table1_id')->references('id')->on('table1'); 
    $table->foreign('table2_id')->references('id')->on('table2'); 

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

}); 
+1

$表 - >獨特的([ 'KEY1', 'KEY2'])下可用索引類型參考文件; –

+0

@BenSwinburne感謝您的提示!請張貼它作爲答案,以便我可以接受它。 – CarlosCarucce

回答

1

您可以將數組傳遞給unique方法。

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

manual