zing / laravel-eloquent-tags
Manage tags for Laravel eloquent
4.0.0
2026-12-03 09:09 UTC
Requires
- php: ^8.2
- illuminate/database: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
Requires (Dev)
- mockery/mockery: ~1.3.3 || ^1.4.2
- orchestra/testbench: ^10.0 || ^11.0
- phpunit/phpunit: ^11.0 || ^12.0 || ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 09:32:13 UTC
README
Requires PHP 8.2+
Require Laravel Eloquent Tags using Composer:
composer require zing/laravel-eloquent-tags
Usage
use Zing\LaravelEloquentTags\Tests\Models\Product; use Zing\LaravelEloquentTags\Tag; $product = Product::query()->first(); // Add tag(s) to model $product->attachTag("tag"); $product->attachTags([ "tag", Tag::query()->first() ]); // Remove tag(s) from model $product->detachTag("tag"); $product->detachTags([ "tag", Tag::query()->first() ]); // Reset tags of model $product->syncTags([ "tag", Tag::query()->first() ]); // Get tags of model $product->tags; // Eager load tags $products = Product::query()->with('tags')->withCount('tags')->get(); $products->each(function (Product $product){ $product->tags->dump(); $product->tags_count; }); // Query by tag Product::query()->withAnyTags(['tag', 'github'])->exists(); // true Product::query()->withAllTags(['tag', 'github'])->exists(); // false
License
Laravel Eloquent Tags is an open-sourced software licensed under the MIT license.