FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow negative condition in presence verifier · JavaDevl/framework@e0c7d76 · GitHub

Commit e0c7d76

Browse files
Roman Kinyakin
committed
Allow negative condition in presence verifier
1 parent 6b461ca commit e0c7d76

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎src/Illuminate/Validation/DatabasePresenceVerifier.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Validation;
44

5+
use Illuminate\Support\Str;
56
use Illuminate\Database\ConnectionResolverInterface;
67

78
class DatabasePresenceVerifier implements PresenceVerifierInterface
@@ -91,6 +92,8 @@ protected function addWhere($query, $key, $extraValue)
9192
$query->whereNull($key);
9293
} elseif ($extraValue === 'NOT_NULL') {
9394
$query->whereNotNull($key);
95+
} elseif (Str::startsWith($extraValue, '!')) {
96+
$query->where($key, '!=', mb_substr($extraValue, 1));
9497
} else {
9598
$query->where($key, $extraValue);
9699
}

‎tests/Validation/ValidationDatabasePresenceVerifierTest.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ public function testBasicCount()
1616
$db->shouldReceive('connection')->once()->with('connection')->andReturn($conn = m::mock('StdClass'));
1717
$conn->shouldReceive('table')->once()->with('table')->andReturn($builder = m::mock('StdClass'));
1818
$builder->shouldReceive('where')->with('column', '=', 'value')->andReturn($builder);
19-
$extra = ['foo' => 'NULL', 'bar' => 'NOT_NULL', 'baz' => 'taylor', 'faz' => true];
19+
$extra = ['foo' => 'NULL', 'bar' => 'NOT_NULL', 'baz' => 'taylor', 'faz' => true, 'not' => '!admin'];
2020
$builder->shouldReceive('whereNull')->with('foo');
2121
$builder->shouldReceive('whereNotNull')->with('bar');
2222
$builder->shouldReceive('where')->with('baz', 'taylor');
2323
$builder->shouldReceive('where')->with('faz', true);
24+
$builder->shouldReceive('where')->with('not', '!=', 'admin');
2425
$builder->shouldReceive('count')->once()->andReturn(100);
2526

2627
$this->assertEquals(100, $verifier->getCount('table', 'column', 'value', null, null, $extra));

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL