khaway/laravel-taxonomy

There is no license information available for the latest version (v0.0.18) of this package.

Laravel taxonomy package.

v0.0.18 2020-09-18 00:39 UTC

README

Inspired by power of WordPress taxonomies, for Laravel Artisans.

<?php

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);