Skip to content

Commit

Permalink
Document dropColumnIfExists()
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers authored Jul 12, 2024
1 parent ff33d9b commit 2b84f6c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions database/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2b84f6c

Please sign in to comment.