|
1
|
|
|
<?php |
|
2
|
|
|
namespace Prateekkarki\Laragen\Models\Types\File; |
|
3
|
|
|
use Prateekkarki\Laragen\Models\TypeResolver; |
|
4
|
|
|
use Prateekkarki\Laragen\Models\Types\FileType; |
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
|
|
7
|
|
|
class MultipleType extends FileType |
|
8
|
|
|
{ |
|
9
|
|
|
protected $hasModel = true; |
|
10
|
|
|
protected $isRelational = true; |
|
11
|
|
|
protected $hasMultipleFiles = true; |
|
12
|
|
|
protected $formType = 'multipleFiles'; |
|
13
|
|
|
protected $stubs = [ |
|
14
|
|
|
'modelMethod' => 'common/Models/fragments/belongsTo', |
|
15
|
|
|
'foreignMethod' => 'common/Models/fragments/hasMany' |
|
16
|
|
|
]; |
|
17
|
|
|
|
|
18
|
|
|
public function getPivotSchema() |
|
19
|
|
|
{ |
|
20
|
|
|
$modelName = $this->getParentModelLowercase(); |
|
21
|
|
|
$moduleName = $this->getParentModule(); |
|
22
|
|
|
$schema = '$table->bigInteger("'.$modelName.'_id")->unsigned()->nullable();'.PHP_EOL.$this->getTabs(3); |
|
23
|
|
|
$schema .= "\$table->foreign('".$modelName."_id')->references('id')->on('".$moduleName."')->onDelete('set null');".PHP_EOL.$this->getTabs(3); |
|
24
|
|
|
$schema .= '$table->string("filename", 192);'.PHP_EOL.$this->getTabs(3); |
|
25
|
|
|
$schema .= '$table->integer("size");'.PHP_EOL.$this->getTabs(3); |
|
26
|
|
|
$schema .= '$table->timestamps();'.PHP_EOL.$this->getTabs(3); |
|
27
|
|
|
return $schema; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getPivotTable() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->getParentModelLowercase()."_".strtolower(Str::plural($this->columnName)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getMigrationPivot() |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->getParentModel().Str::plural($this->getChildModel()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getRelatedModel() |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->getPivot(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getPivot() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->getParentModel().$this->getChildModel(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getPivotColumns() |
|
51
|
|
|
{ |
|
52
|
|
|
$columnModels = []; |
|
53
|
|
|
foreach ($this->getLaragenColumns() as $column => $optionString) { |
|
|
|
|
|
|
54
|
|
|
$columnModels[$column] = TypeResolver::getType($this->getPivotTable(), $column, $optionString); |
|
55
|
|
|
} |
|
56
|
|
|
return $columnModels; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getTypeColumns() |
|
60
|
|
|
{ |
|
61
|
|
|
return [$this->getParentModelLowercase().'_id', 'filename', 'size']; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|