Skip to content

Commit dcbfd68

Browse files
Merge pull request #519 from AlexVanderbist/add-hasTag-documentation
Document the `hasTag` method
2 parents 9e7513c + d1384d2 commit dcbfd68

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ $tag2->order_column; //returns 2
9898

9999
// manipulating the order of tags
100100
$tag->swapOrder($anotherTag);
101+
102+
// checking if a model has a tag
103+
$newsItem->hasTag('first tag');
104+
$newsItem->hasTag('first tag', 'some_type');
101105
```
102106

103107
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

docs/basic-usage/using-tags.md

+16
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,19 @@ You can fetch a collection of all registered tag types by using the static metho
9999
```php
100100
Tag::getTypes();
101101
```
102+
103+
## Checking if a model has a tag
104+
105+
You can check if a model has a specific tag using the `hasTag` method:
106+
107+
```php
108+
$yourModel->hasTag('tag 1'); // returns true if the model has the tag
109+
$yourModel->hasTag('non-existing tag'); // returns false if the model does not have the tag
110+
```
111+
112+
You can also check if a model has a tag with a specific type:
113+
114+
```php
115+
$yourModel->hasTag('tag 1', 'some_type'); // returns true if the model has the tag with the specified type
116+
$yourModel->hasTag('tag 1', 'non-existing type'); // returns false if the model does not have the tag with the specified type
117+
```

0 commit comments

Comments
 (0)