Commit 979dc801 authored by Jens Segers's avatar Jens Segers

Merge pull request #620 from neoxia/master

Fix #607 exists() bug and assure compatibility with Laravel 5.1.19
parents b6139331 e0f39d5f
...@@ -349,6 +349,16 @@ class Builder extends BaseBuilder { ...@@ -349,6 +349,16 @@ class Builder extends BaseBuilder {
} }
} }
/**
* Determine if any rows exist for the current query.
*
* @return bool
*/
public function exists()
{
return ! is_null($this->first());
}
/** /**
* Force the query to only return distinct results. * Force the query to only return distinct results.
* *
......
...@@ -206,6 +206,12 @@ class QueryTest extends TestCase { ...@@ -206,6 +206,12 @@ class QueryTest extends TestCase {
$this->assertEquals(6, $count); $this->assertEquals(6, $count);
} }
public function testExists()
{
$this->assertFalse(User::where('age', '>', 37)->exists());
$this->assertTrue(User::where('age', '<', 37)->exists());
}
public function testSubquery() public function testSubquery()
{ {
$users = User::where('title', 'admin')->orWhere(function ($query) $users = User::where('title', 'admin')->orWhere(function ($query)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment