42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
use Illuminate\Database\Migrations\Migration;
|
||
|
use Illuminate\Database\Schema\Blueprint;
|
||
|
use Illuminate\Support\Facades\Schema;
|
||
|
|
||
|
class AddReferences extends Migration
|
||
|
{
|
||
|
/**
|
||
|
* Run the migrations.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function up()
|
||
|
{
|
||
|
Schema::table('topics', function (Blueprint $table) {
|
||
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||
|
});
|
||
|
|
||
|
Schema::table('replies', function (Blueprint $table) {
|
||
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||
|
$table->foreign('topic_id')->references('id')->on('topics')->onDelete('cascade');
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Reverse the migrations.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function down()
|
||
|
{
|
||
|
Schema::table('topics', function (Blueprint $table) {
|
||
|
$table->dropForeign(['user_id']);
|
||
|
});
|
||
|
|
||
|
Schema::table('replies', function (Blueprint $table) {
|
||
|
$table->dropForeign(['user_id', 'topic_id']);
|
||
|
});
|
||
|
}
|
||
|
}
|