webbingbrasil/laravel-taxonomies

Terms & Taxonomies (similar to WordPress) for Laravel 5.

1.0.1 2024-02-07 18:31 UTC

This package is auto-updated.

Last update: 2024-11-07 20:19:39 UTC


README

Terms & Taxonomies (similar to WordPress) for Laravel 5.

Installation

Install package via composer

composer require "webbingbrasil/laravel-taxonomies=1.0.0"

Next, if you are using Laravel prior to 5.5, register the service provider in the providers array of your config/app.php configuration file:

Cviebrock\EloquentSluggable\ServiceProvider::class,
WebbingBrasil\Taxonomies\Providers\TaxonomyServiceProvider::class,

To get started, you'll need to publish the vendor assets and migrate:

php artisan vendor:publish --provider="WebbingBrasil\Taxonomies\Providers\TaxonomyServiceProvider" && php artisan migrate

Usage

Add our HasTaxonomies trait to your model.

<?php namespace App\Models;

use WebbingBrasil\Taxonomies\Traits\HasTaxonomies;

class Post extends Model
{
    use HasTaxonomies;

    // ...
}
?>

You can also create specific classes of taxonomies

<?php namespace App\Models;

use WebbingBrasil\Taxonomies\AbstractTerm;

class Category extends AbstractTerm
{
    /**
     * Taxonomy name
     *
     * @return string
     */
    public function getTaxonomy()
    {
       return 'category';
    }
    
    // ...
}
?>
<?php namespace App\Models;

use WebbingBrasil\Taxonomies\AbstractTerm;

class Tag extends AbstractTerm
{
    /**
     * Taxonomy name
     *
     * @return string
     */
    public function getTaxonomy()
    {
       return 'tag';
    }
    
    // ...
}
?>