From 2b84f6c17a044d06b2593b2cacabdd85b525b275 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Fri, 12 Jul 2024 00:14:42 -0600 Subject: [PATCH] Document dropColumnIfExists() Refs: https://github.com/wintercms/storm/commit/2fcb050bdbc051c25e0a94485a0a46d0b87dd119 --- database/structure.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/database/structure.md b/database/structure.md index 5a0fbff5..d6a9bd32 100644 --- a/database/structure.md +++ b/database/structure.md @@ -217,6 +217,23 @@ Schema::table('users', function ($table) { }); ``` +You can also use the `dropColumnIfExists` method on the Schema builder for a slightly safer way of handling migrations: + +```php +Schema::table('users', function ($table) { + $table->dropColumnIfExists('single_column'); + // or + $table->dropColumnIfExists('one_column', 'two_column'); + // or + $table->dropColumnIfExists([ + 'one_column', + 'two_column', + 'red_column', + 'blue_column', + ]); +} +``` + ### Creating indexes The schema builder supports several types of indexes. First, let's look at an example that specifies a column's values should be unique. To create the index, we can simply chain the `unique` method onto the column definition: