Download the PHP package edulazaro/laraterms without Composer
On this page you can find all versions of the php package edulazaro/laraterms. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download edulazaro/laraterms
More information about edulazaro/laraterms
Files in edulazaro/laraterms
Package laraterms
Short Description Polymorphic taxonomies for Laravel. Define tags, categories or any custom classification in config. Hierarchical, slug-aware, attach to any model, counts cached, query scopes included.
License MIT
Informations about the package laraterms
Laraterms
Polymorphic taxonomies for Laravel. Define tags, categories or any custom classification in config. Multi-tenant. Multi-locale. Hierarchical or flat. Spatie-compatible. Cross-locale search via auto-maintained search_text. Zero schema opinion beyond two tables.
Installation
Define your taxonomies
config/laraterms.php ships with tags and categories as examples. Edit or add what you need:
Multi-tenant (scope-scoped)
By default taxonomies are tenant-scoped: each scope (Organization, Workspace, Team) has its own isolated terms. Define how to resolve the scope of any taxable model:
Or per model:
The scope can be a Model, an array (['type' => 'organization', 'id' => 5]), a Scope value object, or null (global). It does not require a morph map: it works with FQCN as scope_type.
For taxonomies shared across all tenants (languages, countries), set scope: 'global'.
Make a model taxable
API
Multi-locale (i18n)
Each translatable field has two columns: the canonical one (name, description) and the translations one (name_translations, description_translations). Spatie-compatible (format: {"en": "...", "es": "..."}).
The accessor on name and description resolves automatically: active locale, then fallback locale, then canonical column.
Spatie integration (opt-in, on your side)
If you want the full Spatie API on the *_translations columns:
Our accessor on name/description keeps working because it reads the raw attributes.
Cross-locale search
search_text is auto-maintained in saving() by concatenating all values across all locales. Language-agnostic LIKE search:
Hierarchical
Model
Activate / deactivate (soft hide)
Each term has is_active (default true). Deactivating hides the term from pickers for new attachments, but models already attached keep showing the badge. Useful for "this tag is no longer used, but old posts that have it keep showing it".
This is NOT soft-delete. If you want proper SoftDeletes (with withTrashed, restore, etc.), extend the model in your app:
Merge terms (mergeInto)
For duplicate cleanup ("we had laravel and Laravel Framework, merge them into laravel"):
Guard: both must belong to the same taxonomy and the same scope. Throws InvalidArgumentException otherwise.
Facade
Schema
terms: id, taxonomy, scope_type, scope_id, parent_id, name, name_translations (JSON), handle, description, description_translations (JSON), search_text, color, sort_order, terms_count, meta (JSON), timestamps. Unique on (scope_type, scope_id, taxonomy, handle). FULLTEXT on search_text (best-effort, ignored if the engine does not support it).
termables: polymorphic pivot. term_id, termable_type, termable_id, sort_order, timestamps. Unique on (term_id, termable_type, termable_id).
Table names are configurable.
Exceptions
UnknownTaxonomyException: taxonomy handle not registered.TooManyTermsException: exceedsmax_terms_per_model.RequiresHierarchyException:parent_idset on a flat taxonomy.
License
MIT.