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 $relationalType = 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
|
|
|
$data = new TypeResolver($this->getPivotTable(), $column, $optionString);
|
55
|
|
|
$columnModels[$column] = $data->getLaragenType();
|
56
|
|
|
}
|
57
|
|
|
return $columnModels;
|
58
|
|
|
}
|
59
|
|
|
|
60
|
|
|
public function getTypeColumns()
|
61
|
|
|
{
|
62
|
|
|
return [$this->getParentModelLowercase().'_id', 'filename', 'size'];
|
63
|
|
|
}
|
64
|
|
|
}
|
65
|
|
|
|