create two unique columns in laravel

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'));
$table->unique(['mytext', 'user_id']);
   Schema::create('cal_like', function (Blueprint $table) {
            $table->id();          
            $table->string('module',250)->nullable();
            $table->bigInteger('module_id')->nullable();
            $table->bigInteger('user_id')->nullable();
            $table->unique(array('module_id', 'user_id'));
            $table->timestamps();
        });


Leave a Reply