OptionType::getRelatedModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace Prateekkarki\Laragen\Models\Types\Relational\Single;
3
4
use Prateekkarki\Laragen\Models\Types\Relational\SingleType;
5
use Illuminate\Support\Str;
6
7
class OptionType extends SingleType
8
{
9
    protected $needsTableInit = true;
10
    protected $hasOptions = true;
11
12
    public function getSchema()
13
    {
14
        $schema = "";
15
        $schema .= "\$table->bigInteger('".$this->getForeignKey()."')->unsigned()->nullable();".PHP_EOL.$this->getTabs(3);
16
        $schema .= "\$table->foreign('".$this->getForeignKey()."')->references('id')->on('".$this->getPivotTable()."')->onDelete('set null');".PHP_EOL;
17
        return $schema;
18
    }
19
20
    public function getPivotSchema()
21
    {
22
        $schema = '$table->string("title", 192);'.PHP_EOL.$this->getTabs(3);
23
        $schema .= '$table->timestamps();'.PHP_EOL.$this->getTabs(3);
24
        return $schema;
25
    }
26
27
    public function getRelatedModel()
28
    {
29
        return $this->getPivot();
30
    }
31
32
    public function getPivotTable()
33
    {
34
        return $this->getParentModelLowercase()."_".Str::plural($this->columnName);
35
    }
36
37
    public function getMigrationPivot()
38
    {
39
        return $this->getParentModel().Str::plural(ucfirst(Str::camel($this->columnName)));
40
    }
41
42
    public function getPivot()
43
    {
44
        return $this->getParentModel().ucfirst(Str::camel($this->columnName));
45
    }
46
47
    public function getTypeColumns()
48
    {
49
        return [$this->getParentModelLowercase().'_id', 'title'];
50
    }
51
}
52