Completed
Push — master ( 959c40...94ebcc )
by Abdelrahman
01:16
created

CreateContactRelationsTable::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
use Illuminate\Support\Facades\Schema;
6
use Illuminate\Database\Schema\Blueprint;
7
use Illuminate\Database\Migrations\Migration;
8
9
class CreateContactRelationsTable extends Migration
10
{
11
    public function up()
12
    {
13
        Schema::create(config('rinvex.contacts.tables.contact_relations'), function (Blueprint $table) {
14
            // Columns
15
            $table->integer('contact_id')->unsigned();
16
            $table->integer('related_id')->unsigned();
17
            $table->string('relation');
18
            $table->timestamps();
19
20
            // Indexes
21
            $table->primary(['contact_id', 'related_id']);
22
            $table->foreign('contact_id')->references('id')->on(config('rinvex.contacts.tables.contacts'))
23
                  ->onDelete('cascade')->onUpdate('cascade');
24
            $table->foreign('related_id')->references('id')->on(config('rinvex.contacts.tables.contacts'))
25
                  ->onDelete('cascade')->onUpdate('cascade');
26
        });
27
    }
28
29
    public function down()
30
    {
31
        Schema::dropIfExists(config('rinvex.contacts.tables.contact_relations'));
32
    }
33
}
34