Passed
Pull Request — master (#9)
by Бабичев
02:39
created

CreateTransfersTable::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 20
rs 9.7333
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
use Bavix\Wallet\Models\Transaction;
7
use Bavix\Wallet\Models\Transfer;
8
9
class CreateTransfersTable extends Migration
10
{
11
12
    /**
13
     * @return string
14
     */
15
    protected function transactionTable(): string
16
    {
17
        return (new Transaction())->getTable();
18
    }
19
20
    /**
21
     * @return string
22
     */
23
    protected function table(): string
24
    {
25
        return (new Transfer())->getTable();
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    public function up(): void
32
    {
33
        Schema::create($this->table(), function(Blueprint $table) {
34
            $table->increments('id');
35
            $table->morphs('from');
36
            $table->morphs('to');
37
            $table->unsignedInteger('deposit_id');
38
            $table->unsignedInteger('withdraw_id');
39
            $table->uuid('uuid')->unique();
40
            $table->timestamps();
41
42
            $table->foreign('deposit_id')
43
                ->references('id')
44
                ->on($this->transactionTable())
45
                ->onDelete('cascade');
46
47
            $table->foreign('withdraw_id')
48
                ->references('id')
49
                ->on($this->transactionTable())
50
                ->onDelete('cascade');
51
        });
52
    }
53
54
    /**
55
     * @return void
56
     */
57
    public function down(): void
58
    {
59
        Schema::drop($this->table());
60
    }
61
62
}
63