PHP code example of sohrab-az / laravel-taxonomy

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

    

sohrab-az / laravel-taxonomy example snippets


return [
    'types' => [
        'category' => [
            'label' => 'Category',
            'is_multiple' => true,
            'is_hierarchical' => true,
        ],

        'tag' => [
            'label' => 'Tag',
            'is_multiple' => true,
            'is_hierarchical' => false,
        ],

        'brand' => [
            'label' => 'Brand',
            'is_multiple' => false,
            'is_hierarchical' => false,
        ],
    ],
];

use SohrabAzinfar\Taxonomy\Traits\HasTaxonomies;

class Post extends Model
{
    use HasTaxonomies;
}

$post->taxonomies();

$post->attachTaxonomy($taxonomyId);
$post->attachTaxonomy([1, 2, 3]);

$post->detachTaxonomy($taxonomyId);
$post->detachTaxonomyByType('tag');

$post->syncTaxonomy([1, 2, 3]);
$post->syncTaxonomyByType('category', [1, 2]);

$post->taxonomy()

$post->taxonomy()
    ->type('category')
    ->language('en')
    ->get();

    ->whereSlug('laravel')
    ->whereInSlug(['php', 'laravel'])
    ->whereId(1)
    ->children()
    ->root()

    ->get()
    ->first()
    ->pluck('name')
    ->count()
    ->exists()

app(TaxonomyManager::class)

TaxonomyType::get('category');
TaxonomyType::exists('tag');
TaxonomyType::isMultiple('brand');
TaxonomyType::isHierarchical('category');

TaxonomyServiceProvider
bash
php artisan vendor:publish --tag=taxonomy-config