laravel-taggable maintained by hkp22
Description
Laravel model tagging package.
Author
Last update
2018/07/04 14:01
(dev-master)
License
Downloads
14
Laravel Taggable
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();