1. Go to this page and download the library: Download edulazaro/laraterms library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Single-locale: use only `name`
Term::create(['name' => 'Laravel', 'taxonomy' => 'tags']);
$term->name; // "Laravel"
// Multi-locale
Term::create([
'name' => 'Tag', // canonical fallback
'name_translations' => ['en' => 'Tag', 'es' => 'Etiqueta'],
'taxonomy' => 'tags',
]);
$term->name; // "Etiqueta" if locale=es, "Tag" if locale=en or fallback
class Term extends \EduLazaro\Laraterms\Models\Term
{
use \Spatie\Translatable\HasTranslations;
protected $translatable = ['name_translations', 'description_translations'];
}
Term::search('impuesto')->get(); // matches even if the user is on /en
Term::where('search_text', 'like', '%laravel%')->get();
Term::whereFullText('search_text', 'laravel')->get(); // if your engine supports FULLTEXT (default migration adds it)
use EduLazaro\Laraterms\Support\TermTree;
$tree = TermTree::for('categories'); // Collection of roots with children populated (1 query)
foreach (TermTree::flatten($tree) as [$term, $depth]) {
echo str_repeat('. ', $depth) . $term->name . "\n";
}
$term->ancestors(); // Collection<Term> root to parent
$term->breadcrumb(' > '); // "Tech > Web > Laravel"
$term->descendantIds(); // all descendant ids
$term->deactivate(); // hide from pickers
$term->activate(); // re-activate
Term::active()->inTaxonomy('tags')->forScope($org)->get(); // only active
Term::inactive()->inTaxonomy('tags')->forScope($org)->get(); // only inactive
class Term extends \EduLazaro\Laraterms\Models\Term {
use \Illuminate\Database\Eloquent\SoftDeletes;
}
// + migration with $table->softDeletes();
$dup = Term::byHandle('laravel-framework', 'tags')->first();
$canonical = Term::byHandle('laravel', 'tags')->first();
$dup->mergeInto($canonical, deactivateSource: true);
// 1. Moves all termables from $dup to $canonical (without duplicating)
// 2. Recalculates terms_count on the canonical
// 3. Deactivates $dup (kept in DB but hidden from pickers).
// Pass deactivateSource: false for a real delete with cascade.