@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | { |
54 | 54 | $pdo = DB::connection()->getPdo(); |
55 | 55 | |
56 | - return $pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema="'.$this->database.'"'); |
|
56 | + return $pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema="' . $this->database . '"'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function getTableIndexes($table) |
60 | 60 | { |
61 | 61 | $pdo = DB::connection()->getPdo(); |
62 | 62 | |
63 | - return $pdo->query('SHOW INDEX FROM '.$this->database.'.'.$table.' WHERE Key_name != "PRIMARY"'); |
|
63 | + return $pdo->query('SHOW INDEX FROM ' . $this->database . '.' . $table . ' WHERE Key_name != "PRIMARY"'); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function getTableData($table) |
106 | 106 | { |
107 | - return DB::table($this->database.'.'.$table)->get(); |
|
107 | + return DB::table($this->database . '.' . $table)->get(); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | //end getTableData() |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | $directories = explode($del, $path); |
122 | 122 | foreach ($directories as $directory) { |
123 | 123 | if (!empty($directory)) { |
124 | - $dir .= $del.$directory; |
|
124 | + $dir .= $del . $directory; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | if (!is_dir($dir)) { |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | $schema = $this->compile(); |
91 | 91 | $absolutePath = Config::get('db-exporter.export_path.migrations'); |
92 | 92 | $this->makePath($absolutePath); |
93 | - $this->filename = date('Y_m_d_His').'_create_'.$this->database.'_database.php'; |
|
94 | - static::$filePath = $absolutePath."/{$this->filename}"; |
|
93 | + $this->filename = date('Y_m_d_His') . '_create_' . $this->database . '_database.php'; |
|
94 | + static::$filePath = $absolutePath . "/{$this->filename}"; |
|
95 | 95 | file_put_contents(static::$filePath, $schema); |
96 | 96 | |
97 | 97 | return static::$filePath; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | $down = "Schema::drop('{$value['table_name']}');"; |
127 | - $up = "Schema::create('{$value['table_name']}', function(Blueprint $"."table) {\n"; |
|
127 | + $up = "Schema::create('{$value['table_name']}', function(Blueprint $" . "table) {\n"; |
|
128 | 128 | |
129 | 129 | $tableDescribes = $this->getTableDescribes($value['table_name']); |
130 | 130 | // Loop over the tables fields |
@@ -141,25 +141,25 @@ discard block |
||
141 | 141 | if (in_array($type, ['var', 'varchar', 'double', 'enum', 'decimal', 'float'])) { |
142 | 142 | $para = strpos($values->Type, '('); |
143 | 143 | $opt = substr($values->Type, ($para + 1), -1); |
144 | - $numbers = 'enum' == $type ? ', array('.$opt.')' : ', '.$opt; |
|
144 | + $numbers = 'enum' == $type ? ', array(' . $opt . ')' : ', ' . $opt; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | $method = $this->columnType($type); |
148 | 148 | if ('PRI' == $values->Key) { |
149 | 149 | $tmp = $this->columnType($values->Data_Type, 'primaryKeys'); |
150 | 150 | $method = empty($tmp) ? $method : $tmp; |
151 | - $pri .= empty($tmp) ? ' $'."table->primary('".$values->Field."');\n" : ''; |
|
151 | + $pri .= empty($tmp) ? ' $' . "table->primary('" . $values->Field . "');\n" : ''; |
|
152 | 152 | } |
153 | 153 | |
154 | - $up .= ' $'."table->{$method}('{$values->Field}'{$numbers}){$nullable}{$default}{$unsigned};\n"; |
|
154 | + $up .= ' $' . "table->{$method}('{$values->Field}'{$numbers}){$nullable}{$default}{$unsigned};\n"; |
|
155 | 155 | $up .= $pri; |
156 | 156 | }//end foreach |
157 | 157 | |
158 | - $tableIndexes = (array) $this->getTableIndexes($value['table_name']); |
|
158 | + $tableIndexes = (array)$this->getTableIndexes($value['table_name']); |
|
159 | 159 | if (!is_null($tableIndexes) && count($tableIndexes)) { |
160 | 160 | foreach ($tableIndexes as $index) { |
161 | 161 | if (Str::endsWith(@$index['Key_name'], '_index')) { |
162 | - $up .= ' $'."table->index('".$index['Column_name']."');\n"; |
|
162 | + $up .= ' $' . "table->index('" . $index['Column_name'] . "');\n"; |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
@@ -172,13 +172,13 @@ discard block |
||
172 | 172 | $tableConstraints = $this->getTableConstraints($value['table_name']); |
173 | 173 | if (!is_null($tableConstraints) && $tableConstraints->count()) { |
174 | 174 | $Constraint = $ConstraintDown = " |
175 | - Schema::table('{$value['table_name']}', function(Blueprint $"."table) {\n"; |
|
175 | + Schema::table('{$value['table_name']}', function(Blueprint $" . "table) {\n"; |
|
176 | 176 | $tables = []; |
177 | 177 | foreach ($tableConstraints as $foreign) { |
178 | 178 | if (!in_array($foreign->Field, $tables)) { |
179 | 179 | $field = "{$foreign->Table}_{$foreign->Field}_foreign"; |
180 | - $ConstraintDown .= ' $'."table->dropForeign('".$field."');\n"; |
|
181 | - $Constraint .= ' $'."table->foreign('".$foreign->Field."')->references('".$foreign->References."')->on('".$foreign->ON."')->onDelete('".$foreign->onDelete."');\n"; |
|
180 | + $ConstraintDown .= ' $' . "table->dropForeign('" . $field . "');\n"; |
|
181 | + $Constraint .= ' $' . "table->foreign('" . $foreign->Field . "')->references('" . $foreign->References . "')->on('" . $foreign->ON . "')->onDelete('" . $foreign->onDelete . "');\n"; |
|
182 | 182 | $tables[$foreign->Field] = $foreign->Field; |
183 | 183 | } |
184 | 184 | } |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | }//end if |
246 | 246 | |
247 | 247 | // Grab the template |
248 | - $template = File::get(__DIR__.'/stubs/migration.stub'); |
|
248 | + $template = File::get(__DIR__ . '/stubs/migration.stub'); |
|
249 | 249 | |
250 | 250 | // Replace the classname |
251 | - $template = str_replace('{{name}}', 'Create'.ucfirst(Str::camel($this->database)).'Database', $template); |
|
251 | + $template = str_replace('{{name}}', 'Create' . ucfirst(Str::camel($this->database)) . 'Database', $template); |
|
252 | 252 | |
253 | 253 | // Replace the up and down values |
254 | 254 | $template = str_replace('{{up}}', $upSchema, $template); |