File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -39,12 +39,11 @@ public function hasColumn($table, $column): bool
39
39
*/
40
40
public function hasColumns ($ table , array $ columns ): bool
41
41
{
42
- foreach ($ columns as $ column ) {
43
- if (!$ this ->hasColumn ($ table , $ column )) {
44
- return false ;
45
- }
46
- }
47
- return true ;
42
+ $ collection = $ this ->connection ->table ($ table );
43
+
44
+ return $ collection ->whereAll ($ columns , 'exists ' , true )
45
+ ->project (['_id ' => 1 ])
46
+ ->exists ();
48
47
}
49
48
50
49
/**
Original file line number Diff line number Diff line change @@ -387,8 +387,10 @@ public function testHasColumn(): void
387
387
388
388
public function testHasColumns (): void
389
389
{
390
- DB ::connection ()->collection ('newcollection ' )->insert (['column1 ' => 'value ' ]);
391
- DB ::connection ()->collection ('newcollection ' )->insert (['column2 ' => 'value ' ]);
390
+ // Insert documents with both column1 and column2
391
+ DB ::connection ()->collection ('newcollection ' )->insert ([
392
+ ['column1 ' => 'value1 ' , 'column2 ' => 'value2 ' ]
393
+ ]);
392
394
393
395
$ this ->assertTrue (Schema::hasColumns ('newcollection ' , ['column1 ' , 'column2 ' ]));
394
396
$ this ->assertFalse (Schema::hasColumns ('newcollection ' , ['column1 ' , 'column3 ' ]));
You can’t perform that action at this time.
0 commit comments