@@ -36,17 +36,17 @@ |
||
36 | 36 | |
37 | 37 | public function getPivot() |
38 | 38 | { |
39 | - return $this->getParentModel() . $this->getChildModel(); |
|
39 | + return $this->getParentModel().$this->getChildModel(); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function getMigrationPivot() |
43 | 43 | { |
44 | - return $this->getParentModel() . Str::plural($this->getChildModel()); |
|
44 | + return $this->getParentModel().Str::plural($this->getChildModel()); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function getPivotTable() |
48 | 48 | { |
49 | - return $this->getParentModelLowercase(). "_" . strtolower(Str::plural($this->columnName)); |
|
49 | + return $this->getParentModelLowercase()."_".strtolower(Str::plural($this->columnName)); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function getPivotColumns() |
@@ -8,7 +8,7 @@ |
||
8 | 8 | class RelatedType extends MultipleType |
9 | 9 | { |
10 | 10 | protected $hasPivot = true; |
11 | - protected $formType = 'related'; |
|
11 | + protected $formType = 'related'; |
|
12 | 12 | protected $stubs = [ |
13 | 13 | 'foreignMethod' => 'common/Models/fragments/belongsToMany' |
14 | 14 | ]; |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | $schema .= '$table->bigInteger("'.$this->getParentKey().'")->unsigned()->nullable();'.PHP_EOL.$this->getTabs(3); |
21 | 21 | $schema .= '$table->foreign("'.$this->getParentKey().'")->references("id")->on("'.$moduleName.'")->onDelete("set null");'.PHP_EOL.$this->getTabs(3); |
22 | 22 | |
23 | - $schema .= '$table->bigInteger("'. $this->getChildKey() .'")->unsigned()->nullable();'.PHP_EOL.$this->getTabs(3); |
|
23 | + $schema .= '$table->bigInteger("'.$this->getChildKey().'")->unsigned()->nullable();'.PHP_EOL.$this->getTabs(3); |
|
24 | 24 | $schema .= '$table->foreign("'.$this->getChildKey().'")->references("id")->on("'.$this->typeOption.'")->onDelete("set null");'.PHP_EOL; |
25 | 25 | |
26 | 26 | return $schema; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | public function getChildKey() |
45 | 45 | { |
46 | - return Str::singular($this->columnName) ."_id"; |
|
46 | + return Str::singular($this->columnName)."_id"; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | public function getChildModel() |
@@ -89,6 +89,6 @@ discard block |
||
89 | 89 | |
90 | 90 | public function getTypeColumns() |
91 | 91 | { |
92 | - return [$this->getParentModelLowercase().'_id', strtolower(Str::singular($this->typeOption)) . '_id']; |
|
92 | + return [$this->getParentModelLowercase().'_id', strtolower(Str::singular($this->typeOption)).'_id']; |
|
93 | 93 | } |
94 | 94 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | protected $hasSingleRelation = true; |
9 | 9 | protected $size = false; |
10 | 10 | protected $relationalType = false; |
11 | - protected $formType = 'parent'; |
|
11 | + protected $formType = 'parent'; |
|
12 | 12 | |
13 | 13 | protected $stubs = [ |
14 | 14 | 'modelMethod' => 'common/Models/fragments/hasOne', |
@@ -20,13 +20,13 @@ |
||
20 | 20 | return 'exists:'.$this->getRelatedModule().',id'; |
21 | 21 | } |
22 | 22 | |
23 | - public function hasSelfParent(){ |
|
23 | + public function hasSelfParent() { |
|
24 | 24 | return ($this->typeOption == $this->getParentModule() || $this->typeOption == "self"); |
25 | 25 | } |
26 | 26 | |
27 | 27 | public function getColumnKey() |
28 | 28 | { |
29 | - return $this->columnName . "_id"; |
|
29 | + return $this->columnName."_id"; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | ]); |
27 | 27 | } |
28 | 28 | |
29 | - if(app('laragen')->generatorExists('Frontend\\Controller')){ |
|
29 | + if (app('laragen')->generatorExists('Frontend\\Controller')) { |
|
30 | 30 | $this->insertIntoFile( |
31 | 31 | $webRouteFile, |
32 | 32 | "<?php\n", |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $generatedFiles[] = $webRouteFile; |
42 | 42 | } |
43 | 43 | |
44 | - if(app('laragen')->generatorExists('Backend\\Controller')){ |
|
44 | + if (app('laragen')->generatorExists('Backend\\Controller')) { |
|
45 | 45 | $this->insertIntoFile( |
46 | 46 | $backendWebRouteFile, |
47 | 47 | "<?php\n", |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $generatedFiles[] = $backendWebRouteFile; |
57 | 57 | } |
58 | 58 | |
59 | - if(app('laragen')->generatorExists('Backend\\Api')){ |
|
59 | + if (app('laragen')->generatorExists('Backend\\Api')) { |
|
60 | 60 | $this->insertIntoFile( |
61 | 61 | $backendApiRouteFile, |
62 | 62 | "<?php\n", |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | file_put_contents($fullFilePath, $modelTemplate); |
22 | 22 | $generatedFiles[] = $fullFilePath; |
23 | 23 | |
24 | - foreach($this->module->getFilteredColumns('hasPivot') as $type){ |
|
24 | + foreach ($this->module->getFilteredColumns('hasPivot') as $type) { |
|
25 | 25 | $typeTemplate = $this->buildTemplate('common/Models/Pivot', [ |
26 | 26 | '{{pivotName}}' => $type->getPivot(), |
27 | 27 | '{{massAssignables}}' => implode("', '", $type->getTypeColumns()), |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | $generatedFiles[] = $fullFilePath; |
33 | 33 | } |
34 | 34 | |
35 | - foreach($this->module->getFilteredColumns(['hasModel', 'hasOptions']) as $type){ |
|
35 | + foreach ($this->module->getFilteredColumns(['hasModel', 'hasOptions']) as $type) { |
|
36 | 36 | $pivotModel = Str::singular($type->getPivot()); |
37 | 37 | $typeTemplate = $this->buildTemplate('common/Models/Model', [ |
38 | 38 | '{{modelName}}' => $pivotModel, |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | protected function getUsedModels($pivotModel = false) { |
67 | 67 | $usedModels = ""; |
68 | 68 | $classes = []; |
69 | - foreach($this->module->getFilteredColumns(['hasSingleRelation', 'hasPivot', 'hasModel']) as $type){ |
|
69 | + foreach ($this->module->getFilteredColumns(['hasSingleRelation', 'hasPivot', 'hasModel']) as $type) { |
|
70 | 70 | $model = $type->getRelatedModel(); |
71 | 71 | $class = ($model == 'User') ? config('laragen.options.user_model') : "App\\Models\\".$model; |
72 | - if(in_array($class, $classes) || $model == $this->module->getModelName() || $model == $pivotModel){ |
|
72 | + if (in_array($class, $classes) || $model == $this->module->getModelName() || $model == $pivotModel) { |
|
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | $classes[] = $class; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | protected function getForeignMethods() |
82 | 82 | { |
83 | 83 | $foreignMethods = ""; |
84 | - foreach($this->module->getFilteredColumns(['hasPivot', 'hasSingleRelation', 'hasModel']) as $type){ |
|
84 | + foreach ($this->module->getFilteredColumns(['hasPivot', 'hasSingleRelation', 'hasModel']) as $type) { |
|
85 | 85 | $stub = $type->getStub('foreignMethod') ?: 'common/Models/fragments/hasOne'; |
86 | 86 | $foreignMethods .= $this->buildTemplate($stub, [ |
87 | 87 | '{{columnName}}' => $type->getColumn(), |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | '{{relatedModel}}' => $type->getRelatedModel(), |
90 | 90 | '{{table}}' => $type->getPivotTable(), |
91 | 91 | '{{parentModel}}' => $type->getParentModel(), |
92 | - '{{parentId}}' => $type->getParentModelLowercase() . "_id", |
|
92 | + '{{parentId}}' => $type->getParentModelLowercase()."_id", |
|
93 | 93 | '{{childId}}' => $type->getChildKey(), |
94 | 94 | ]); |
95 | 95 | } |
@@ -11,11 +11,11 @@ discard block |
||
11 | 11 | |
12 | 12 | public function generate() |
13 | 13 | { |
14 | - if(self::$counter==0){ |
|
14 | + if (self::$counter == 0) { |
|
15 | 15 | $existingMigrationFiles = is_dir(database_path('migrations/laragen/')) ? scandir(database_path('migrations/laragen/')) : []; |
16 | 16 | |
17 | 17 | foreach ($existingMigrationFiles as $file) { |
18 | - $file = database_path("migrations/laragen") . "/" . $file; |
|
18 | + $file = database_path("migrations/laragen")."/".$file; |
|
19 | 19 | if (is_file($file)) |
20 | 20 | unlink($file); |
21 | 21 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | $generatedFiles = []; |
25 | 25 | |
26 | - foreach($this->module->getFilteredColumns('needsTableInit') as $type){ |
|
26 | + foreach ($this->module->getFilteredColumns('needsTableInit') as $type) { |
|
27 | 27 | $migrationTemplate = $this->buildTemplate('common/migrations/pivot', [ |
28 | 28 | '{{pivotName}}' => $type->getMigrationPivot(), |
29 | 29 | '{{pivotTableName}}' => $type->getPivotTable(), |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | file_put_contents($fullFilePath, $migrationTemplate); |
47 | 47 | $generatedFiles[] = $fullFilePath; |
48 | 48 | |
49 | - foreach($this->module->getFilteredColumns(['hasPivot']) as $type){ |
|
49 | + foreach ($this->module->getFilteredColumns(['hasPivot']) as $type) { |
|
50 | 50 | $migrationTemplate = $this->buildTemplate('common/migrations/pivot', [ |
51 | 51 | '{{pivotName}}' => $type->getMigrationPivot(), |
52 | 52 | '{{pivotTableName}}' => $type->getPivotTable(), |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | { |
74 | 74 | $fileCounter = sprintf('%06d', (int) date('His') + ++self::$counter); |
75 | 75 | $filenamePrefix = date('Y_m_d_').$fileCounter."_"; |
76 | - $fileName = "create_". $related->getPivotTable()."_table.php"; |
|
76 | + $fileName = "create_".$related->getPivotTable()."_table.php"; |
|
77 | 77 | |
78 | 78 | return $this->getPath("database/migrations/laragen/").$filenamePrefix.$fileName; |
79 | 79 | } |
@@ -16,8 +16,9 @@ |
||
16 | 16 | |
17 | 17 | foreach ($existingMigrationFiles as $file) { |
18 | 18 | $file = database_path("migrations/laragen") . "/" . $file; |
19 | - if (is_file($file)) |
|
20 | - unlink($file); |
|
19 | + if (is_file($file)) { |
|
20 | + unlink($file); |
|
21 | + } |
|
21 | 22 | } |
22 | 23 | } |
23 | 24 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $generatedFiles = []; |
48 | 48 | |
49 | - if($this::$initializeFlag == 0){ |
|
49 | + if ($this::$initializeFlag == 0) { |
|
50 | 50 | $laragen = app('laragen'); |
51 | 51 | $modules = $laragen->getModules(); |
52 | 52 | $permissions = []; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | $permissionsCode = ''; |
69 | 69 | foreach ($allPermissions as $permission) { |
70 | - $permissionsCode .= "Permission::create(['name' => '". $permission ."']);" . PHP_EOL. $this->getTabs(2); |
|
70 | + $permissionsCode .= "Permission::create(['name' => '".$permission."']);".PHP_EOL.$this->getTabs(2); |
|
71 | 71 | |
72 | 72 | } |
73 | 73 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | file_put_contents($fullFilePath, $factoryTemplate); |
94 | 94 | $generatedFiles[] = $fullFilePath; |
95 | 95 | |
96 | - foreach($this->module->getFilteredColumns(['hasPivot']) as $type){ |
|
96 | + foreach ($this->module->getFilteredColumns(['hasPivot']) as $type) { |
|
97 | 97 | $typeTemplate = $this->buildTemplate('common/Factories/Factory', [ |
98 | 98 | '{{modelName}}' => $type->getPivot(), |
99 | 99 | '{{usedModels}}' => $this->getUsedModels($type->getFilteredColumns('hasSingleRelation'), $type->getPivot()), |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | |
119 | 119 | $classes = [$model]; |
120 | 120 | |
121 | - foreach($types as $type){ |
|
121 | + foreach ($types as $type) { |
|
122 | 122 | $model = $type->getRelatedModel(); |
123 | 123 | $class = ($model == 'User') ? config('laragen.options.user_model') : "App\\Models\\".$model; |
124 | - if(in_array($class, $classes)){ |
|
124 | + if (in_array($class, $classes)) { |
|
125 | 125 | continue; |
126 | 126 | } |
127 | 127 | $classes[] = $class; |
@@ -136,8 +136,7 @@ discard block |
||
136 | 136 | foreach ($columns as $type) { |
137 | 137 | $specialTypes = array_keys($this->specialTypesToDefinition); |
138 | 138 | $dataDefinition .= in_array($type->getColumn(), $specialTypes) ? |
139 | - $this->getTabs(2)."'{$type->getColumn()}'"." => ".'$faker->'.$this->specialTypesToDefinition[$type->getColumn()] : |
|
140 | - $this->getTabs(2)."'{$type->getColumn()}'"." => ".'$faker->'.$this->typeToDefinition[$type->getDataType()]; |
|
139 | + $this->getTabs(2)."'{$type->getColumn()}'"." => ".'$faker->'.$this->specialTypesToDefinition[$type->getColumn()] : $this->getTabs(2)."'{$type->getColumn()}'"." => ".'$faker->'.$this->typeToDefinition[$type->getDataType()]; |
|
141 | 140 | $dataDefinition .= ",".PHP_EOL; |
142 | 141 | } |
143 | 142 | return $dataDefinition; |
@@ -146,8 +145,8 @@ discard block |
||
146 | 145 | protected function getForeignData($types) { |
147 | 146 | $foreignData = ""; |
148 | 147 | |
149 | - foreach($types as $type){ |
|
150 | - if($type->hasSelfParent()) continue; |
|
148 | + foreach ($types as $type) { |
|
149 | + if ($type->hasSelfParent()) continue; |
|
151 | 150 | $foreignData .= $this->buildTemplate('common/Factories/fragments/options', [ |
152 | 151 | '{{parent}}' => $type->getColumnKey(), |
153 | 152 | '{{parentModel}}' => $type->getRelatedModel() |
@@ -174,7 +173,7 @@ discard block |
||
174 | 173 | false |
175 | 174 | ); |
176 | 175 | |
177 | - foreach($this->module->getFilteredColumns(['needsTableInit']) as $type){ |
|
176 | + foreach ($this->module->getFilteredColumns(['needsTableInit']) as $type) { |
|
178 | 177 | |
179 | 178 | $this->insertIntoFile( |
180 | 179 | $laragenSeederFile, |
@@ -183,14 +182,14 @@ discard block |
||
183 | 182 | false |
184 | 183 | ); |
185 | 184 | |
186 | - $seedData = PHP_EOL.$this->getTabs(2). "if(".$type->getPivot()."::all()->count()==0){"; |
|
187 | - $seedData .= PHP_EOL.$this->getTabs(3). "DB::table('".$type->getPivotTable()."')->insert(["; |
|
188 | - foreach($type->getDbData() as $title){ |
|
185 | + $seedData = PHP_EOL.$this->getTabs(2)."if(".$type->getPivot()."::all()->count()==0){"; |
|
186 | + $seedData .= PHP_EOL.$this->getTabs(3)."DB::table('".$type->getPivotTable()."')->insert(["; |
|
187 | + foreach ($type->getDbData() as $title) { |
|
189 | 188 | $seedData .= PHP_EOL.$this->getTabs(4); |
190 | - $seedData .= "['title' => '" . $title . "'],"; |
|
189 | + $seedData .= "['title' => '".$title."'],"; |
|
191 | 190 | } |
192 | - $seedData .= PHP_EOL.$this->getTabs(3). "]);"; |
|
193 | - $seedData .= PHP_EOL.$this->getTabs(2). "}"; |
|
191 | + $seedData .= PHP_EOL.$this->getTabs(3)."]);"; |
|
192 | + $seedData .= PHP_EOL.$this->getTabs(2)."}"; |
|
194 | 193 | |
195 | 194 | $this->insertIntoFile( |
196 | 195 | $laragenSeederFile, |
@@ -199,7 +198,7 @@ discard block |
||
199 | 198 | ); |
200 | 199 | } |
201 | 200 | |
202 | - foreach($this->module->getFilteredColumns(['hasPivot']) as $type){ |
|
201 | + foreach ($this->module->getFilteredColumns(['hasPivot']) as $type) { |
|
203 | 202 | |
204 | 203 | $this->insertIntoFile( |
205 | 204 | $laragenSeederFile, |
@@ -211,7 +210,7 @@ discard block |
||
211 | 210 | $this->insertIntoFile( |
212 | 211 | $laragenSeederFile, |
213 | 212 | "\n // End factories", |
214 | - "\n".$this->getTabs(2)."factory(".$type->getPivot()."::class, ".(int)config('laragen.options.seed_rows') * 2 .")->create();", |
|
213 | + "\n".$this->getTabs(2)."factory(".$type->getPivot()."::class, ".(int) config('laragen.options.seed_rows') * 2.")->create();", |
|
215 | 214 | false |
216 | 215 | ); |
217 | 216 | } |
@@ -147,7 +147,9 @@ |
||
147 | 147 | $foreignData = ""; |
148 | 148 | |
149 | 149 | foreach($types as $type){ |
150 | - if($type->hasSelfParent()) continue; |
|
150 | + if($type->hasSelfParent()) { |
|
151 | + continue; |
|
152 | + } |
|
151 | 153 | $foreignData .= $this->buildTemplate('common/Factories/fragments/options', [ |
152 | 154 | '{{parent}}' => $type->getColumnKey(), |
153 | 155 | '{{parentModel}}' => $type->getRelatedModel() |
@@ -63,7 +63,7 @@ |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | public function getCleanPath($file) { |
66 | - return realpath(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
66 | + return realpath(dirname($file)).DIRECTORY_SEPARATOR.basename($file); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | public function initializeFiles($fileMaps = []) { |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | |
83 | 83 | protected function getForeignData() { |
84 | 84 | $foreignData = ""; |
85 | - $parents = $this->module->getFilteredColumns(['hasPivot','hasSingleRelation']); |
|
85 | + $parents = $this->module->getFilteredColumns(['hasPivot', 'hasSingleRelation']); |
|
86 | 86 | $columns = []; |
87 | 87 | foreach ($parents as $type) { |
88 | 88 | $column = $type->getRelatedModule(); |
89 | - if(!in_array($column, $columns)){ |
|
89 | + if (!in_array($column, $columns)) { |
|
90 | 90 | $foreignData .= "'".$column."' => ".$type->getRelatedModel()."::all(),".PHP_EOL.$this->getTabs(3); |
91 | 91 | $columns[] = $column; |
92 | 92 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | $usedModels = "use ".$namespace.$this->module->getModelName().";"; |
100 | 100 | |
101 | 101 | $classes = [$namespace.$this->module->getModelName()]; |
102 | - foreach($this->module->getFilteredColumns(['hasSingleRelation', 'hasPivot', 'hasModel']) as $type){ |
|
102 | + foreach ($this->module->getFilteredColumns(['hasSingleRelation', 'hasPivot', 'hasModel']) as $type) { |
|
103 | 103 | $model = $type->getRelatedModel(); |
104 | 104 | $class = ($model == 'User') ? config('laragen.options.user_model') : "App\\Models\\".$model; |
105 | - if(in_array($class, $classes)){ |
|
105 | + if (in_array($class, $classes)) { |
|
106 | 106 | continue; |
107 | 107 | } |
108 | 108 | $classes[] = $class; |
@@ -29,7 +29,9 @@ discard block |
||
29 | 29 | $relatedUpdates = ""; |
30 | 30 | $relatedTypes = $this->module->getFilteredColumns(['hasPivot']); |
31 | 31 | |
32 | - if (empty($relatedTypes)) return ""; |
|
32 | + if (empty($relatedTypes)) { |
|
33 | + return ""; |
|
34 | + } |
|
33 | 35 | if (count($relatedTypes) > 1) { |
34 | 36 | $relatedUpdates .= $this->buildTemplate('backend/fragments/related-create', [ |
35 | 37 | '{{modelNameLowercase}}' => $this->module->getModelNameLowercase(), |
@@ -47,7 +49,9 @@ discard block |
||
47 | 49 | protected function getRelatedUpdates() { |
48 | 50 | $relatedUpdates = ""; |
49 | 51 | $relatedTypes = $this->module->getFilteredColumns(['hasPivot']); |
50 | - if (empty($relatedTypes)) return ""; |
|
52 | + if (empty($relatedTypes)) { |
|
53 | + return ""; |
|
54 | + } |
|
51 | 55 | if (count($relatedTypes) > 1) { |
52 | 56 | $relatedUpdates .= $this->buildTemplate('backend/fragments/related-process', [ |
53 | 57 | '{{modelNameLowercase}}' => $this->module->getModelNameLowercase(), |
@@ -65,7 +69,9 @@ discard block |
||
65 | 69 | protected function getFileUploads() { |
66 | 70 | $fileUploads = ""; |
67 | 71 | $fileFields = $this->module->getFilteredColumns(['hasFile']); |
68 | - if (empty($fileFields)) return ""; |
|
72 | + if (empty($fileFields)) { |
|
73 | + return ""; |
|
74 | + } |
|
69 | 75 | if (count($fileFields) > 1) { |
70 | 76 | $fileUploads .= $this->buildTemplate('backend/fragments/upload-process', [ |
71 | 77 | '{{modelNameLowercase}}' => $this->module->getModelNameLowercase(), |