PHPackages                             birdcar/laravel-label-graph - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. birdcar/laravel-label-graph

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

birdcar/laravel-label-graph
===========================

A Laravel package for managing hierarchical labels as a DAG with materialized path routes

1.1.0(3mo ago)10MITPHPPHP ^8.3CI passing

Since Feb 2Pushed 3mo agoCompare

[ Source](https://github.com/birdcar/laravel-label-graph)[ Packagist](https://packagist.org/packages/birdcar/laravel-label-graph)[ RSS](/packages/birdcar-laravel-label-graph/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (5)Used By (0)

Laravel Label Graph
===================

[](#laravel-label-graph)

[![CI](https://github.com/birdcar/laravel-label-graph/actions/workflows/ci.yaml/badge.svg)](https://github.com/birdcar/laravel-label-graph/actions/workflows/ci.yaml)[![Latest Version on Packagist](https://camo.githubusercontent.com/f89728c76f444c802934d0664305a7513cc5f39e41009def9540c496246c38ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626972646361722f6c61726176656c2d6c6162656c2d67726170682e737667)](https://packagist.org/packages/birdcar/laravel-label-graph)[![Total Downloads](https://camo.githubusercontent.com/dbbf8c4612267fbf5cd498bb9ec3f210a6349aba8145dc028c70e5968be24d05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626972646361722f6c61726176656c2d6c6162656c2d67726170682e737667)](https://packagist.org/packages/birdcar/laravel-label-graph)[![License](https://camo.githubusercontent.com/ad1f5c4c2e4df77a9528466a08e8e363bbc0a7b78e72283820f216bdbe7fe376/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626972646361722f6c61726176656c2d6c6162656c2d67726170682e737667)](https://packagist.org/packages/birdcar/laravel-label-graph)

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 &gt; Mice" AND "Gaming &gt; Accessories".

Perfect For
-----------

[](#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
-------

[](#not-for)

- **Simple flat tags**: Use [spatie/laravel-tags](https://github.com/spatie/laravel-tags) instead
- **Single-parent trees**: Consider [kalnoy/nestedset](https://github.com/lazychaser/laravel-nestedset) if you don't need multi-parent

Installation
------------

[](#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
-----------

[](#quick-start)

### Create Labels

[](#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

[](#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

[](#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
-------------

[](#documentation)

Full documentation available at [birdcar.github.io/laravel-label-graph](https://birdcar.github.io/laravel-label-graph)

- [When to Use](https://birdcar.github.io/laravel-label-graph/#/when-to-use) - Decision guide for package selection
- [Package Comparison](https://birdcar.github.io/laravel-label-graph/#/comparison) - vs spatie/laravel-tags, kalnoy/nestedset
- [Implementation Guide](https://birdcar.github.io/laravel-label-graph/#/llm-implementation-brief) - Complete integration walkthrough
- [Installation](https://birdcar.github.io/laravel-label-graph/#/installation)
- [Models &amp; Relationships](https://birdcar.github.io/laravel-label-graph/#/models)
- [HasLabels Trait](https://birdcar.github.io/laravel-label-graph/#/traits)
- [Query Scopes &amp; Patterns](https://birdcar.github.io/laravel-label-graph/#/query-scopes)
- [Query Cookbook](https://birdcar.github.io/laravel-label-graph/#/llm-query-cookbook) - 20+ query examples
- [Architecture](https://birdcar.github.io/laravel-label-graph/#/architecture)

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 11.0+ or 12.0+
- SQLite, MySQL 8.0+, or PostgreSQL 14+

Contributing
------------

[](#contributing)

Contributions are welcome! Please read our contributing guidelines before submitting a PR.

1. Fork the repository
2. Create your feature branch: `git checkout -b feature/amazing-feature`
3. Run tests: `./vendor/bin/pest`
4. Run linting: `./vendor/bin/pint && ./vendor/bin/phpstan analyse`
5. Commit your changes with a descriptive message
6. Push to your branch and create a Pull Request

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance82

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

98d ago

Major Versions

0.1.0 → 1.0.02026-02-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ae7d6c0d0d79964baa8983329873cf76933ddec22faee5e1a4bcf3dd4efb7ea?d=identicon)[birdcar](/maintainers/birdcar)

---

Top Contributors

[![birdcar](https://avatars.githubusercontent.com/u/434063?v=4)](https://github.com/birdcar "birdcar (36 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/birdcar-laravel-label-graph/health.svg)

```
[![Health](https://phpackages.com/badges/birdcar-laravel-label-graph/health.svg)](https://phpackages.com/packages/birdcar-laravel-label-graph)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
