0% found this document useful (0 votes)
12 views1 page

Reference

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Reference

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

<?

php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateReferencesAndModifyResolutionsTable extends Migration


{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
// Create the 'references' table
Schema::create('references', function (Blueprint $table) {
$table->id(); // Auto-incrementing primary key
$table->string('title', 300); // Title column (not nullable)
$table->timestamps(); // Adds created_at and updated_at columns
});

// Modify the 'resolutions' table to add the 'reference_id' column


Schema::table('resolutions', function (Blueprint $table) {
// Add the reference_id column to the resolutions table
$table->unsignedBigInteger('reference_id')->nullable()-
>after('category_id');

// Add the foreign key constraint if necessary


$table->foreign('reference_id')->references('id')->on('references')-
>onDelete('set null');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
// Drop the foreign key constraint
Schema::table('resolutions', function (Blueprint $table) {
$table->dropForeign(['reference_id']);
$table->dropColumn('reference_id');
});

// Drop the 'references' table


Schema::dropIfExists('references');
}
}

You might also like