Skip to content

Commit

Permalink
[7.x] Add isNotFilled() method to Request (#33732)
Browse files Browse the repository at this point in the history
* [7.x] Add empty() method to Request

* Change to isNotFilled
  • Loading branch information
KennedyTedesco authored Aug 5, 2020
1 parent 278c224 commit 71ebdca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ public function filled($key)
return true;
}

/**
* Determine if the request contains an empty value for an input item.
*
* @param string|array $key
* @return bool
*/
public function isNotFilled($key)
{
$keys = is_array($key) ? $key : func_get_args();

foreach ($keys as $value) {
if (! $this->isEmptyString($value)) {
return false;
}
}

return true;
}

/**
* Determine if the request contains a non-empty value for any of the given inputs.
*
Expand Down
17 changes: 17 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,23 @@ public function testFilledMethod()
$this->assertTrue($request->filled('foo.bar'));
}

public function testIsNotFilledMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);
$this->assertFalse($request->isNotFilled('name'));
$this->assertTrue($request->isNotFilled('age'));
$this->assertTrue($request->isNotFilled('city'));
$this->assertTrue($request->isNotFilled('foo'));
$this->assertFalse($request->isNotFilled(['name', 'email']));
$this->assertTrue($request->isNotFilled(['foo', 'age']));
$this->assertTrue($request->isNotFilled(['age', 'city']));

$request = Request::create('/', 'GET', ['foo' => ['bar', 'baz' => '0']]);
$this->assertFalse($request->isNotFilled('foo'));
$this->assertTrue($request->isNotFilled('foo.bar'));
$this->assertFalse($request->isNotFilled('foo.baz'));
}

public function testFilledAnyMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);
Expand Down

0 comments on commit 71ebdca

Please sign in to comment.