Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Add isNotFilled() method to Request #33732

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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