Skip to content

Commit

Permalink
Merge pull request #519 from AlexVanderbist/add-hasTag-documentation
Browse files Browse the repository at this point in the history
Document the `hasTag` method
  • Loading branch information
AlexVanderbist authored Oct 3, 2024
2 parents 9e7513c + d1384d2 commit dcbfd68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ $tag2->order_column; //returns 2

// manipulating the order of tags
$tag->swapOrder($anotherTag);

// checking if a model has a tag
$newsItem->hasTag('first tag');
$newsItem->hasTag('first tag', 'some_type');
```

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).
Expand Down
16 changes: 16 additions & 0 deletions docs/basic-usage/using-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,19 @@ You can fetch a collection of all registered tag types by using the static metho
```php
Tag::getTypes();
```

## Checking if a model has a tag

You can check if a model has a specific tag using the `hasTag` method:

```php
$yourModel->hasTag('tag 1'); // returns true if the model has the tag
$yourModel->hasTag('non-existing tag'); // returns false if the model does not have the tag
```

You can also check if a model has a tag with a specific type:

```php
$yourModel->hasTag('tag 1', 'some_type'); // returns true if the model has the tag with the specified type
$yourModel->hasTag('tag 1', 'non-existing type'); // returns false if the model does not have the tag with the specified type
```

0 comments on commit dcbfd68

Please sign in to comment.