Skip to content

Instantly share code, notes, and snippets.

@Cerwyn
Last active April 17, 2020 04:52
Show Gist options
  • Save Cerwyn/914975b20d625c6a3313bf47379de967 to your computer and use it in GitHub Desktop.
Save Cerwyn/914975b20d625c6a3313bf47379de967 to your computer and use it in GitHub Desktop.
One-to-many
<?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