schema builder laravel migrations unique on two columns

前端 未结 3 1605
离开以前
离开以前 2020-12-23 08:47

How can I set a unique constraints on two columns?

class MyModel extends Migration {
  public function up()
  {
    Schema::create(\'storage_trackers\', fun         


        
3条回答
  •  有刺的猬
    2020-12-23 09:17

    The second param is to manually set the name of the unique index. Use an array as the first param to create a unique key across multiple columns.

    $table->unique(array('mytext', 'user_id'));
    

    or (a little neater)

    $table->unique(['mytext', 'user_id']);
    

提交回复
热议问题