diff --git a/README.md b/README.md index c9fd7ec..257dea5 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ $book->addMeta('someKey', 'someValue'); $book->getMeta('someKey'); +$book->hasMeta('someKey'); + $book->updateMeta('someKey', 'anotherValue'); $book->deleteMeta('someKey'); diff --git a/src/Metable.php b/src/Metable.php index fcd07c4..8c1e24a 100644 --- a/src/Metable.php +++ b/src/Metable.php @@ -14,6 +14,19 @@ public function getAllMeta() return collect($this->meta->pluck('value', 'key')); } + /** + * Has meta. + * + * @param string $key + * @return bool + */ + public function hasMeta($key) + { + $meta = $this->meta()->where('key', $key)->get(); + + return (bool) count($meta); + } + /** * Get meta. *