PHP code example of trexology / taxonomy

1. Go to this page and download the library: Download trexology/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/ */

    

trexology / taxonomy example snippets


'Trexology\Taxonomy\TaxonomyServiceProvider',

'Taxonomy'        => 'Trexology\Taxonomy\Facades\TaxonomyFacade',



class Car extends \Eloquent {
  use \Trexology\Taxonomy\TaxonomyTrait;
}

'Trexology\Taxonomy\TaxonomyServiceProvider',

'Taxonomy' => 'Trexology\Taxonomy\Facades\TaxonomyFacade',



class Car extends \Eloquent {
  use \Trexology\Taxonomy\TaxonomyTrait;
}

Taxonomy::createVocabulary('Cars');

$vocabulary = Taxonomy::getVocabulary(1);             // Using ID
$vocabulary = Taxonomy::getVocabularyByName('Cars');  // Using Name

Taxonomy::deleteVocabulary(1);             // Using ID
Taxonomy::deleteVocabularyByName('Cars');  // Using Name

Taxonomy::createTerm($vocabulary->id, 'Audi');

$german_cars = Taxonomy::createTerm($vocabulary->id, 'German Cars');
$italian_cars = Taxonomy::createTerm($vocabulary->id, 'Italian Cars');

$term_audi = Taxonomy::CreateTerm($vocabulary->id, 'Audi', $german_cars->id, 0);
$term_bmw  = Taxonomy::CreateTerm($vocabulary->id, 'BMW', $german_cars->id, 1);
$term_benz = Taxonomy::CreateTerm($vocabulary->id, 'Mercedes-Benz', $german_cars->id, 2);
$term_ferrari = Taxonomy::CreateTerm($vocabulary->id, 'Ferrari', $italian_cars->id, 0);

$params = [
	'shortname' => "GC",
	'type' => "Premium Cars",
];
$german_cars = Taxonomy::CreateTerm($vocabulary->id, 'BMW', $german_cars->id, 0, $params)

$car = Car::create([
  'model' => 'A3',
]);

$car->addTerm($term_bmw->id);
$car->addTerm($term_benz->id);
$car->removeAllTerms();              // Remove all terms linked to this car

$car->addTerm($term_ferrari->id);
$car->removeTerm($term_ferrari-id);  // Remove a specific term

$car->addTerm($term_audi->id);

// Get all the terms from the vocabulary 'Cars' That
// are attached to this Car.
$terms = $car->getTermsByVocabularyName('Cars');

$audis = Car::getAllByTermId($term_audi->id)->get();

Route::resource('taxonomy', '\Trexology\Taxonomy\Controllers\TaxonomyController');
Route::post('postOrderTerms', '\Trexology\Taxonomy\Controllers\TaxonomyController@postOrderTerms');
Route::resource('terms', '\Trexology\Taxonomy\Controllers\TermsController');