1. Go to this page and download the library: Download fomvasss/laravel-taxonomy 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/ */
fomvasss / laravel-taxonomy example snippets
public function txArticleCategories()
{
return $this->termsByVocabulary('article_categories');
}
\App\Models\Taxonomy\Term::find(1)->vocabulary; // get system name vocabulary
\App\Models\Taxonomy\Term::find(1)->txVocabulary; // get related model vocabulary
\App\Models\Taxonomy\Term::byVocabulary('article_categories')->get(); // get terms by system name vocabulary
\App\Models\Taxonomy\Term::byVocabulary('article_categories')->get()->toTree(); // `toTree` - method from package `lazychaser/laravel-nestedset`
\App\Models\Taxonomy\Term::find(1)->descendants; // `descendants` - method from package `lazychaser/laravel-nestedset`
\App\Models\Article::with('txArticleCategories')->get(); // get articles with article categories
\App\Models\Article::first()->txArticleCategories()->attach([1, 2]);
\App\Models\Article::first()->txArticleCategories()->sync([4, 2]); // this detach all terms in article and sync 4 ,2!!! Same as:
\App\Models\Article::first()->terms()->sync([4, 2]);
\App\Models\Article::first()->terms()->detach([4]);
\App\Models\Article::first()->txArticleCategories()->syncWithoutDetaching([4, 2]); // sync terms without detaching
\App\Models\Article::byTaxonomies([
'article_categories' => [1,3,5],
'cities' => [3]
])->get(); // use for example for filters