Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Illuminate/View/ComponentAttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ public function has($key)
return array_key_exists($key, $this->attributes);
}

/**
* Determine if a given attribute is missing from the attribute array.
*
* @param string $key
* @return bool
*/
public function missing($key)
{
return ! $this->has($key, $this->attributes);
}

/**
* Only include the given attribute from the attribute array.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/View/ViewComponentAttributeBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,14 @@ public function testAttributeRetrieval()
'test-extract-2' => 'defaultValue',
]));
}

public function testAttibuteExistence()
{
$bag = new ComponentAttributeBag(['name' => 'test']);

$this->assertTrue((bool) $bag->has('name'));
$this->assertFalse((bool) $bag->missing('name'));
$this->assertFalse((bool) $bag->has('class'));
$this->assertTrue((bool) $bag->missing('class'));
}
}