Created
February 18, 2020 16:43
-
-
Save alcir-junior-caju/e84869e4c40b0598b867acbe819d5be1 to your computer and use it in GitHub Desktop.
Error Migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class CreateCouponsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('coupons', function (Blueprint $table) { | |
$table->bigIncrements('id'); | |
$table->string('title'); | |
$table->string('slug') | |
->unique(); | |
$table->enum('status', ['ACTIVE', 'INACTIVE']) | |
->default('ACTIVE'); | |
$table->string('school') | |
->nullable(); | |
$table->string('description') | |
->nullable(); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('coupons'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class CreateCodesTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('codes', function (Blueprint $table) { | |
$table->bigIncrements('id'); | |
$table->string('title'); | |
$table->string('slug') | |
->unique(); | |
$table->enum('status', ['ACTIVE', 'INACTIVE']) | |
->default('ACTIVE'); | |
$table->date('expired_date'); | |
$table->char('code', 12); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('codes'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class AddCouponIdUserIdToCodesTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::table('codes', function (Blueprint $table) { | |
$table->unsignedBigInteger('coupon_id'); | |
$table->foreign('coupon_id') | |
->references('id') | |
->on('coupons') | |
->onUpdate('cascade') | |
->onDelete('set null'); | |
$table->unsignedBigInteger('user_id'); | |
$table->foreign('user_id') | |
->references('id') | |
->on('users') | |
->onUpdate('cascade') | |
->onDelete('set null'); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::table('codes', function (Blueprint $table) { | |
$table->dropForeign('users_user_id_foreign'); | |
$table->dropColumn('user_id'); | |
$table->dropForeign('coupons_coupon_id_foreign'); | |
$table->dropColumn('coupon_id'); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment