定制 sourcedopen/tags 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sourcedopen/tags

最新稳定版本:1.0.0

Composer 安装命令:

composer require sourcedopen/tags

包简介

A laravel package for tags

README 文档

README

A Laravel package for adding tags to Eloquent models using polymorphic relationships.

Installation

You can install the package via Composer:

composer require sourcedopen/tags

The package will automatically register its service provider.

Configuration

Publish and run the migrations:

php artisan vendor:publish --tag="tags-migrations"
php artisan migrate

Usage

Adding Tags to a Model

Use the HasTags trait in any model you want to be taggable:

use Illuminate\Database\Eloquent\Model;
use SourcedOpen\Tags\Traits\HasTags;

class Post extends Model
{
    use HasTags;
}

Creating Tags

use SourcedOpen\Tags\Models\Tag;

$tag = Tag::create([
    'name' => 'Laravel',
    'color' => '#FF2D20', // Optional hex color code
]);

Attaching Tags

// Attach a single tag
$post->attachTags($tag->id);

// Attach multiple tags
$post->attachTags([$tag1->id, $tag2->id]);

Detaching Tags

// Detach a single tag
$post->detachTags($tag->id);

// Detach multiple tags
$post->detachTags([$tag1->id, $tag2->id]);

Syncing Tags

// Sync tags (removes all existing and attaches the provided ones)
$post->syncTags([$tag1->id, $tag2->id]);

Retrieving Tags

// Get all tags for a model
$tags = $post->tags;

// Query with tags
$posts = Post::whereHas('tags', function ($query) {
    $query->where('name', 'Laravel');
})->get();

Testing

composer test

Or run Pest directly:

./vendor/bin/pest

Code Style

This package uses Laravel Pint for code styling:

./vendor/bin/pint

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-06