Skip to content

Commit 979dc80

Browse files
committed
Merge pull request #620 from neoxia/master
Fix #607 exists() bug and assure compatibility with Laravel 5.1.19
2 parents b613933 + e0f39d5 commit 979dc80

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ public function aggregate($function, $columns = [])
349349
}
350350
}
351351

352+
/**
353+
* Determine if any rows exist for the current query.
354+
*
355+
* @return bool
356+
*/
357+
public function exists()
358+
{
359+
return ! is_null($this->first());
360+
}
361+
352362
/**
353363
* Force the query to only return distinct results.
354364
*

tests/QueryTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ public function testCount()
206206
$this->assertEquals(6, $count);
207207
}
208208

209+
public function testExists()
210+
{
211+
$this->assertFalse(User::where('age', '>', 37)->exists());
212+
$this->assertTrue(User::where('age', '<', 37)->exists());
213+
}
214+
209215
public function testSubquery()
210216
{
211217
$users = User::where('title', 'admin')->orWhere(function ($query)

0 commit comments

Comments
 (0)