PHP code example of khaway / laravel-taxonomy

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

    

khaway / laravel-taxonomy example snippets




use Scrapify\LaravelTaxonomy\Models\Taxonomies\NestedTaxonomy;
use Scrapify\LaravelTaxonomy\InteractsWithTaxonomies;

class ProductCategory extends NestedTaxonomy
{
    public static $singleTableType = 'product_category';
}

class Product
{
    use InteractsWithTaxonomies;

    public function categories()
    {
        return $this->morphToManyTaxonomies(ProductCategory::class);
    }
}

$productCategory = ProductCategory::create(['Notebooks']);

Product::create(['name' => 'Apple MacBook'])
    ->categories()
    ->sync($productCategory->id);