birdcar/laravel-label-graph
Composer 安装命令:
composer require birdcar/laravel-label-graph
包简介
A Laravel package for managing hierarchical labels as a DAG with materialized path routes
README 文档
README
Laravel package for hierarchical labels with multiple parents (DAG), lquery pattern matching (priority.*, *.bug), and materialized path routes for fast queries. Unlike traditional trees, labels can belong to multiple hierarchies—a "Wireless Gaming Mouse" can appear in both "Electronics > Mice" AND "Gaming > Accessories".
Perfect For
- E-commerce categories: Products in multiple categories
- Issue tracker labels: GitHub-style hierarchical labels with pattern queries
- Content taxonomy: Nested topics with fast ancestor/descendant lookups
- Permission hierarchies: Complex permission structures with multiple inheritance
Not For
- Simple flat tags: Use spatie/laravel-tags instead
- Single-parent trees: Consider kalnoy/nestedset if you don't need multi-parent
Installation
composer require birdcar/laravel-label-graph
Publish and run migrations:
php artisan vendor:publish --tag=label-graph-migrations php artisan migrate
Optionally publish the config:
php artisan vendor:publish --tag=label-graph-config
Quick Start
Create Labels
use Birdcar\LabelGraph\Models\Label; use Birdcar\LabelGraph\Models\LabelRelationship; // Create root labels $priority = Label::create(['name' => 'Priority']); $high = Label::create(['name' => 'High']); $critical = Label::create(['name' => 'Critical']); // Create hierarchy LabelRelationship::create([ 'parent_label_id' => $priority->id, 'child_label_id' => $high->id, ]); LabelRelationship::create([ 'parent_label_id' => $high->id, 'child_label_id' => $critical->id, ]); // Routes are automatically generated: // priority // priority.high // priority.high.critical
Attach Labels to Models
use Birdcar\LabelGraph\Models\Concerns\HasLabels; class Ticket extends Model { use HasLabels; } // Attach routes by path $ticket->attachRoute('priority.high.critical'); $ticket->attachRoute('type.bug'); // Query by exact route Ticket::whereHasRoute('priority.high')->get(); // Query by pattern (lquery-style: * matches zero or more labels) Ticket::whereHasRouteMatching('priority.*')->get(); // priority and descendants Ticket::whereHasRouteMatching('*.bug')->get(); // any path ending in bug // Query descendants/ancestors Ticket::whereHasRouteDescendantOf('priority')->get(); Ticket::whereHasRouteAncestorOf('priority.high.critical')->get();
Query Routes Directly
use Birdcar\LabelGraph\Models\LabelRoute; // Find routes by pattern LabelRoute::wherePathMatches('priority.*')->get(); // Find descendants of a path LabelRoute::whereDescendantOf('priority')->get(); // Find ancestors of a path LabelRoute::whereAncestorOf('priority.high.critical')->get();
Documentation
Full documentation available at birdcar.github.io/laravel-label-graph
- When to Use - Decision guide for package selection
- Package Comparison - vs spatie/laravel-tags, kalnoy/nestedset
- Implementation Guide - Complete integration walkthrough
- Installation
- Models & Relationships
- HasLabels Trait
- Query Scopes & Patterns
- Query Cookbook - 20+ query examples
- Architecture
Requirements
- PHP 8.3+
- Laravel 11.0+ or 12.0+
- SQLite, MySQL 8.0+, or PostgreSQL 14+
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting a PR.
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Run tests:
./vendor/bin/pest - Run linting:
./vendor/bin/pint && ./vendor/bin/phpstan analyse - Commit your changes with a descriptive message
- Push to your branch and create a Pull Request
License
The MIT License (MIT). See LICENSE for details.
birdcar/laravel-label-graph 适用场景与选型建议
birdcar/laravel-label-graph 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 birdcar/laravel-label-graph 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 birdcar/laravel-label-graph 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-03