nickdekruijk/taggable

Make your Laravel models taggable

1.0.5 2022-05-16 15:17 UTC

This package is auto-updated.

Last update: 2024-11-16 21:11:46 UTC


README

Latest Stable Version Latest Unstable Version Monthly Downloads Total Downloads License

Taggable

Make your Laravel models taggable

Installation

composer require nickdekruijk/taggable

Config

If you don't like the default configuration edit config/taggable.php after publishing the config file with:

php artisan vendor:publish --tag=config --provider="NickDeKruijk\Taggable\ServiceProvider"

Run migration

Then run the migration

php artisan migrate

Usage

Add the Taggable trait to your model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use NickDeKruijk\Taggable\Taggable;

class Product extends Model
{
    use Taggable;

Admin package integration

If you are using nickdekruijk/admin add this to your config/admin.php file to manage tags:

        'tags' => [
            'view' => 'admin::model',
            'icon' => 'fa-tags',
            'model' => 'NickDeKruijk\Taggable\Tag',
            'index' => 'title',
            'active' => 'active',
            'orderBy' => 'sort',
            'sortable' => true,
            'treeview' => 'parent',
            'columns' => [
                'active',
                'title',
            ],
        ],

And add a column to the model you made taggable:

                'tags' => [
                    'type' => 'pivot',
                    'model' => 'NickDeKruijk\Taggable\Tag',
                    'morph' => 'taggable',
                    'scope' => 'getTree',
                    'columns' => 'title',
                    'treeview' => 'parent',
                ],

License

Admin is open-sourced software licensed under the MIT license.