1
|
|
|
<?php |
2
|
|
|
namespace Prateekkarki\Laragen\Models\Types\Relational\Multiple; |
3
|
|
|
use Prateekkarki\Laragen\Models\TypeResolver; |
4
|
|
|
use Prateekkarki\Laragen\Models\Types\Relational\MultipleType; |
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
|
7
|
|
|
class MultipleDataType extends MultipleType |
8
|
|
|
{ |
9
|
|
|
protected $hasModel = true; |
10
|
|
|
protected $isMultipleType = true; |
11
|
|
|
protected $formType = 'multiple'; |
12
|
|
|
protected $stubs = [ |
13
|
|
|
'modelMethod' => 'common/Models/fragments/belongsTo', |
14
|
|
|
'foreignMethod' => 'common/Models/fragments/hasMany' |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
public function getPivotSchema() |
18
|
|
|
{ |
19
|
|
|
$schema = PHP_EOL.$this->getTabs(3); |
20
|
|
|
foreach ($this->getPivotColumns() as $type) { |
21
|
|
|
$schema .= $type->getSchema().PHP_EOL.$this->getTabs(3); |
22
|
|
|
} |
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 getDisplay() |
33
|
|
|
{ |
34
|
|
|
return strtolower(Str::singular(str_replace("_", " ", $this->columnName))); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getPivot() |
38
|
|
|
{ |
39
|
|
|
return $this->getParentModel().$this->getChildModel(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getMigrationPivot() |
43
|
|
|
{ |
44
|
|
|
return $this->getParentModel().Str::plural($this->getChildModel()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getPivotTable() |
48
|
|
|
{ |
49
|
|
|
return $this->getParentModelLowercase()."_".strtolower(Str::plural($this->columnName)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getPivotColumns() |
53
|
|
|
{ |
54
|
|
|
$columns = []; |
55
|
|
|
foreach ($this->getLaragenColumns() as $column => $optionString) { |
|
|
|
|
56
|
|
|
$columns[$column] = TypeResolver::getType($this->getPivotTable(), $column, $optionString); |
57
|
|
|
} |
58
|
|
|
return $columns; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getTypeColumns() |
62
|
|
|
{ |
63
|
|
|
return [$this->columnName, $this->getParentModelLowercase().'_id']; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|