Last active
April 17, 2020 04:52
-
-
Save Cerwyn/914975b20d625c6a3313bf47379de967 to your computer and use it in GitHub Desktop.
One-to-many
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\Support\Facades\Schema; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateCommentsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('comments', function (Blueprint $table) { | |
$table->bigIncrements('id'); | |
$table->bigInteger('article_id')->unsigned(); | |
$table->string('text'); | |
$table->integer('star'); | |
$table->timestamps(); | |
$table->foreign('article_id') | |
->references('id') | |
->on('articles') | |
->onCascade('delete'); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('comments'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment