Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Aug 27, 2018
1 parent b549d29 commit 55398e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,30 @@ class BlogPost extends Resource
}
```

Now you can view and add tags on the blog posts screen in your Nova app. Any tags will be saved in the `tags` table.
Now you can view and add tags on the blog posts screen in your Nova app. All tags will be saved in the `tags` table.

For more info on how to work with the save tags, head over to [the docs of spatie/laravel-tags](https://docs.spatie.be/laravel-tags/).
## Using types

The [underlying tags package](https://github.com/spatie/laravel-tags) has support for [tag types](https://docs.spatie.be/laravel-tags/v2/advanced-usage/using-types). To make your tags field save tags of a certain type just tack on the name of type when adding the field to your Nova resource.

```php
// in your Nova resource

public function fields(Request $request)
{
return [
// ...

Tags::make('Tags')->type('my-special-type'),

// ...
];
}
```

## Working with tags

For more info on how to work with the saved tags, head over to [the docs of spatie/laravel-tags](https://docs.spatie.be/laravel-tags/).

### Testing

Expand Down
7 changes: 6 additions & 1 deletion src/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class Tags extends Field
{
public $component = 'nova-tags-field';

public function type(string $type)
{
return $this->withMeta(['type' => $type]);
}

protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{
$requestValue = $request[$requestAttribute];
Expand All @@ -19,7 +24,7 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
$class = get_class($model);

$class::saved(function($model) use ($tagNames) {
$model->syncTags($tagNames);
$model->syncTagsWithType($tagNames, $this->meta()['type'] ?? null);
});
}

Expand Down

0 comments on commit 55398e3

Please sign in to comment.