Skip to content

Commit 4fef190

Browse files
committed
Fix compatibility with Laravel 10
1 parent 2150aba commit 4fef190

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/Schema/Builder.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use MongoDB\Model\CollectionInfo;
99
use MongoDB\Model\IndexInfo;
1010

11+
use function array_fill_keys;
1112
use function array_keys;
1213
use function assert;
1314
use function count;
@@ -25,31 +26,24 @@ class Builder extends \Illuminate\Database\Schema\Builder
2526
*
2627
* @param string $table
2728
* @param string $column
28-
*
29-
* @return bool
3029
*/
3130
public function hasColumn($table, $column): bool
3231
{
33-
$collection = $this->connection->table($table);
34-
35-
return $collection->where($column, 'exists', true)
36-
->project(['_id' => 1])
37-
->exists();
32+
return $this->hasColumns($table, [$column]);
3833
}
3934

4035
/**
4136
* Check if columns exists in the collection schema.
4237
*
4338
* @param string $table
4439
* @param string[] $columns
45-
*
46-
* @return bool
4740
*/
4841
public function hasColumns($table, array $columns): bool
4942
{
5043
$collection = $this->connection->table($table);
5144

52-
return $collection->whereAll($columns, 'exists', true)
45+
return $collection
46+
->where(array_fill_keys($columns, ['$exists' => true]))
5347
->project(['_id' => 1])
5448
->exists();
5549
}

tests/SchemaTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ public function testHasColumns(): void
395395
// Insert documents with both column1 and column2
396396
DB::connection()->collection('newcollection')->insert([
397397
['column1' => 'value1', 'column2' => 'value2'],
398+
['column1' => 'value3'],
398399
]);
399400

400401
$this->assertTrue(Schema::hasColumns('newcollection', ['column1', 'column2']));

0 commit comments

Comments
 (0)