hkp22 / laravel-taggable
Laravel model tagging package.
1.0
2018-07-04 12:01 UTC
Requires
- php: >=5.5.0
- illuminate/database: >= 5.0
- illuminate/support: >= 5.0
Requires (Dev)
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~5.0
- vlucas/phpdotenv: ~2.0
This package is auto-updated.
Last update: 2024-10-21 20:41:38 UTC
README
Laravel Eloquent model tagging package.
Installation
You can install the package via composer:
composer require hkp22/laravel-taggable
Usage
Prepare Taggable model
use Hkp22\LaravelTaggable\Traits\Taggable; use Illuminate\Database\Eloquent\Model as Eloquent; class Lesson extends Eloquent { use Taggable; }
Registering package
Include the service provider within app/config/app.php
:
'providers' => [ Hkp22\LaravelTaggable\TaggableServiceProvider::class, ],
Tag Eloquent model
Eg: Tagging a lesson Model.
$lesson->tag(['laravel', 'php']);
or
$tags = $tags = Tag::whereIn('slug', ['laravel', 'testing'])->get(); $lesson->tag($tags);
Un-tag eloquent model
Eg: Un-tagging lesson model.
// Un-tag single tag. $lesson->untag(['laravel']); // Un-tag all tags. $lesson->untag();
Re-tag eloquent model
// Tag $lesson->tag(['laravel', 'testing']); // Re-tag $lesson->retag(['laravel', 'postgres', 'redis']);
Total tagged entities count.
$tag = Tag::first(); $tag->count;
Get model with any given tag
$lessons = Lesson::withAnyTag(['php'])->get();
Get model with only given tag
$lessons = Lesson::withAllTags(['php', 'laravel', 'testing'])->get();