Introduction | laravel-tags-go | Spatie       

 SPATIE  

laravel-tags-go
===============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-tags-go](https://spatie.be/docs/laravel-tags-go/v1)  Introduction

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-tags-go/v1) 

  Introduction    
- [ Introduction ](https://spatie.be/docs/laravel-tags-go/v1/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-tags-go/v1/postcardware)
- [ Requirements ](https://spatie.be/docs/laravel-tags-go/v1/requirements)
- [ Installation and setup ](https://spatie.be/docs/laravel-tags-go/v1/installation-and-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-tags-go/v1/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-tags-go/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-tags-go/v1/about-us)
- [ Testing ](https://spatie.be/docs/laravel-tags-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-tags-go/v1/releasing)
- [ Support us ](https://spatie.be/docs/laravel-tags-go/v1/support-us)

Basic usage
-----------

- [ Using tags ](https://spatie.be/docs/laravel-tags-go/v1/basic-usage/using-tags)
- [ Retrieving tagged models ](https://spatie.be/docs/laravel-tags-go/v1/basic-usage/retrieving-tagged-models)

Advanced usage
--------------

- [ Adding translations ](https://spatie.be/docs/laravel-tags-go/v1/advanced-usage/adding-translations)
- [ Using types ](https://spatie.be/docs/laravel-tags-go/v1/advanced-usage/using-types)
- [ Sorting tags ](https://spatie.be/docs/laravel-tags-go/v1/advanced-usage/sorting-tags)
- [ Using your own tag model ](https://spatie.be/docs/laravel-tags-go/v1/advanced-usage/using-your-own-tag-model)
- [ Using another default locale ](https://spatie.be/docs/laravel-tags-go/v1/advanced-usage/using-another-default-locale)

  Laravel-tags-go 
=================

 Add tags and taggable behaviour to Laravel Go models 

### Useful links

- [Repository](https://github.com/spatie/laravel-tags-go)
- [Discussions](https://github.com/spatie/laravel-tags-go/discussions)

Introduction
------------

###  On this page 

1. [ Differences from PHP ](#content-differences-from-php)

This package adds taggable behaviour to your Laravel Go models. Identify a saved model with its morph alias and numeric key to attach tags to it.

Laravel Tags supports [translating tags](advanced-usage/adding-translations), [multiple tag types](advanced-usage/using-types) and [sorting tags](advanced-usage/sorting-tags).

Here are some code examples:

```
manager := tags.From(ctx)
owner := tags.Owner{Type: "posts", ID: post.ID}

err := manager.Attach(ctx, owner, tags.Names("tag", "tag2"), tags.Selection{})
if err != nil {
    return err
}

err = manager.Sync(ctx, owner, tags.Names("tag1", "tag2"), tags.Selection{})
if err != nil {
    return err
}

query, err := manager.Filter(ctx, model.Query[Post](), "posts.id", "posts",
    tags.Names("tag1", "tag2"), tags.Selection{}, tags.All)
if err != nil {
    return err
}
posts, err := query.Get(ctx)
```

Differences from PHP
--------------------------------------------------------------------------------------------------------------------

Go has no Eloquent traits or attribute mutators. Create the owner first, then attach tags in the same `db.Transaction` when both writes must succeed together. Call `DetachAll` from the owner's native `Deleting` hook for automatic cleanup. Bulk deletes bypass that hook.

Use the manager's `Create` and `Save` methods to generate localized slugs and initial order. Direct ORM and bulk writes bypass tag preparation. Custom native model hooks still run when the manager writes models.

The default schema uses numeric keys on one database connection. Custom tables, numeric key columns, model fields and pivot behavior are supported through an adapter and custom migrations. UUID and string keys require a different storage adapter and are not supported by this release's API.

Names cannot be blank. Name and slug lookup uses the exact requested locale, without fallback. Slugs use Laravel Go's ASCII transliteration, which can differ from PHP's transliteration tables for some languages. Configure a slugger when exact imported slugs matter.

`FindOrCreate` avoids duplicates within a batch and reuses existing matches. Like the PHP schema, translated JSON maps have no database-wide unique constraint. Concurrent writers may create duplicate names. Serialize writes at the application boundary when you require strict uniqueness.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
