File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
src/Illuminate/Database/Schema Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,36 @@ public function hasColumns($table, array $columns)
170
170
return true ;
171
171
}
172
172
173
+ /**
174
+ * Execute a callback inside table builder if has a column
175
+ *
176
+ * @param string $table
177
+ * @param string $column
178
+ * @param \Closure $callback
179
+ * @return void
180
+ */
181
+ public function whenTableHasColumn (string $ table , string $ column , Closure $ callback ): void
182
+ {
183
+ if ($ this ->hasColumn ($ table , $ column )) {
184
+ $ this ->table ($ table , fn (Blueprint $ table ) => $ callback ($ table ));
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Execute a callback inside table builder if does't have a column
190
+ *
191
+ * @param string $table
192
+ * @param string $column
193
+ * @param \Closure $callback
194
+ * @return void
195
+ */
196
+ public function whenTableHasNotColumn (string $ table , string $ column , Closure $ callback ): void
197
+ {
198
+ if (! $ this ->hasColumn ($ table , $ column )) {
199
+ $ this ->table ($ table , fn (Blueprint $ table ) => $ callback ($ table ));
200
+ }
201
+ }
202
+
173
203
/**
174
204
* Get the data type for the given column name.
175
205
*
You can’t perform that action at this time.
0 commit comments