Installation | laravel-tags-rust | Spatie       

 SPATIE  

laravel-tags-rust
=================

spatie.be/open-source

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

 Version   v1      

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

  Installation    
- [ Introduction ](https://spatie.be/docs/laravel-tags-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-tags-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/laravel-tags-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-tags-rust/v1/usage)
- [ Custom models ](https://spatie.be/docs/laravel-tags-rust/v1/custom-models)
- [ Database contracts ](https://spatie.be/docs/laravel-tags-rust/v1/database)
- [ Changelog ](https://spatie.be/docs/laravel-tags-rust/v1/changelog)
- [ Testing ](https://spatie.be/docs/laravel-tags-rust/v1/testing)

 Installation
============

###  On this page 

1. [ Model identity ](#content-model-identity)
2. [ Configuration ](#content-configuration)
3. [ Fresh schema ](#content-fresh-schema)

- Requires Rust 1.99+ and `laravel-rust =0.1.0`.
- Cargo fetches public package-tools and Translatable dependencies at the revisions pinned in Cargo.toml.
- Registry publication is disabled.

```
[dependencies]
spatie-laravel-tags = { path = "../laravel-tags-rust" }
laravel = { package = "laravel-rust", version = "=0.1.0", default-features = false, features = ["database-sqlite"] }
serde = { version = "1", features = ["derive"] }
```

SQLite is the default feature. `mysql` and `postgres` enable the framework's other drivers. Use `default-features = false` when selecting another driver. The current translatable dependency also enables SQLite transitively.

Model identity
--------------------------------------------------------------------------------------------------

```
use laravel::model::model;
use spatie_tags::HasTags;

#[model(morph = "App\\Models\\Post")]
pub struct Post {
    pub id: i64,
    pub title: String,
}

impl HasTags for Post {
    type Tag = spatie_tags::Tag;
}
```

The morph string must equal the database's `taggable_type` value, including case and backslashes. Do not change it when renaming a Rust struct. Numeric `i64` keys are supported. Owners and tags must share a connection. A [custom tag model](custom-models) can select a named connection with `#[model(connection = "...")]`; assignment reads, writes, transactions and ordering follow that connection. Use `Taggable::new(alias, id)` when no Rust model is available.

Register owner-deletion cleanup in the application's native event configuration:

```
laravel::Application::configure()
    .with_events(|events, _| spatie_tags::listen::<Post>(events));
```

Bulk deletes and writes that suppress model events bypass the listener. Clean up their assignments explicitly in the same transaction.

Configuration
-----------------------------------------------------------------------------------------------

Default settings work without registration. Add the package-tools provider to read environment settings, then use `with_config` for application overrides:

```
use spatie_tags::Config;

let app = laravel::Application::configure()
    .with_providers(|providers| {
        providers.add(spatie_tags::service_provider());
    })
    .with_config(|config, _| {
        config.section_mut::<Config>().slugger =
            |name, _locale| name.to_lowercase().replace(' ', "_");
    })
    .create();
```

- `TAGS_TABLE` selects the assignment table, defaulting to `taggables`.
- `TAGS_MORPH_NAME` selects the owner-column prefix, defaulting to `taggable`.
- `Config::slugger` receives the name and locale. Its default transliterates to lowercase ASCII.
- Select model types through `HasTags::Tag` and native typed relations, not environment strings.
- Application overrides run after provider defaults, regardless of builder call order.
- If you configure everything manually, use `Config::from_env(env)` in `with_config` without a provider.
- Choose the same assignment layout in your migrations and native relations.
- Changing configuration does not rename existing tables or columns.
- Keep the application's migration wrapper explicit. Registering the provider does not execute migrations.

Fresh schema
--------------------------------------------------------------------------------------------

Add this file to your application's migration directory and register it with `db::migrations!`:

```
use laravel::db::AnyTransaction;

pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> {
    spatie_tags::migrate(tx).await
}
```

The migration creates `tags` and `taggables` with timestamps, a unique pivot key, and cascading tag deletion. Do not run it against existing tables. Use your application's normal migration runner and backup policy; the package does not inspect or alter production data.

 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)
