Database Migration for Company Contacts in Laravel

This snippet defines a database migration in a Laravel application to create a 'company_contact' table. It includes relations to contact and company IDs, and additional fields like 'is_point_of_contact' and 'roles'. The migration also includes a method to reverse the changes if necessary.
mail@pastecode.io avatar
unknown
php
20 days ago
825 B
4
Indexable
Never
<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('company_contact', function (Blueprint $table) {
            $table->id();
            $table->foreignId('contact_id')->constrained();
            $table->foreignId('company_id')->constrained();
            $table->boolean('is_point_of_contact');
            $table->json('roles')->nullable();
            $table->unique(['contact_id', 'company_id']);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('company_contacts');
    }
};
Leave a Comment