# Tags Model

The `Tags` model is designed to categorize and tag different entities within the application. This functionality allows users to organize content such as clips, articles, and products effectively. Tags help improve searchability and organization across the platform.

## Tags Table

### Fields

- **id**:
    - A unique identifier for each tag. This number is automatically generated by the system to distinguish each tag.

- **name**:
    - A JSON field that contains the name(s) of the tag. This allows for multilingual support or different aliases for the same tag.

- **slug**:
    - A JSON field that provides a URL-friendly version of the tag name. This is often used in routes or links to improve SEO and user experience.

- **type**:
    - An optional string field that can define the type of the tag. This allows for categorizing tags further if needed.

- **order_column**:
    - An optional integer field that indicates the order in which tags should be displayed. This enables custom sorting of tags.

- **timestamps**:
    - Boolean fields for `created_at` and `updated_at`. These fields automatically store the creation and modification timestamps for each tag.

## Taggables Table

The `taggables` table serves as a pivot table for the many-to-many relationship between tags and other entities (like clips, articles, and products). It allows multiple entities to share the same tag and vice versa.

### Fields

- **tag_id**:
    - A foreign key that references the `id` in the `tags` table. It establishes the relationship between a tag and the tagged entity. Deleting a tag will cascade the delete operation to this table.

- **taggable**:
    - This morphs into two fields: `taggable_id` and `taggable_type`, allowing various models to be tagged (e.g., clips, articles, products). The `taggable_type` indicates which model is being tagged.

- **unique constraint**:
    - Ensures that a combination of `tag_id`, `taggable_id`, and `taggable_type` is unique. This prevents duplicate entries for the same tag on the same entity.

## Tag Management with Spatie

Tags are managed using the `spatie/laravel-tags` package, which provides a robust and convenient API for tagging functionality. This package allows you to easily manage and retrieve tags associated with various entities.

### Taggable Entities

The tagging system is flexible and can be used across multiple entity types, such as:

- **Clips**
- **Posts**
- **Products**

Each of these entities can be tagged with relevant keywords, allowing users to filter or search by tags efficiently.

---

This structure outlines the `Tags` model and its relationship with the `taggables` table, highlighting the robustness of the tagging system and its management via the `spatie/laravel-tags` package. The document is designed to be clear and accessible for users with varying levels of technical knowledge.