Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Ltree

Laravel Ltree Laravel Package

happenv-com/laravel-ltree

Laravel integration for PostgreSQL's ltree extension, making it easy to store and query hierarchical data such as categories, menus, and org trees. Supports path-based ancestor/descendant lookups, subtree moves, and Eloquent model traits for managing tree structures directly in your database.

View on GitHub
Deep Wiki
Context7

Package exposes postgres-ltree extension through an expressive Laravel API.

Frequently asked questions about Laravel Ltree
What is happenv-com/laravel-ltree used for?
It is a Laravel integration for PostgreSQL's ltree extension, which stores hierarchical data as a dot-delimited path string in a single column. You use it to model trees such as categories, navigation menus, comment threads, and org charts, then query ancestors and descendants with path operators instead of recursive CTEs. The package exposes that through an Eloquent-friendly API with model traits, casts, and query scopes. It only works on PostgreSQL.
How do I install laravel-ltree and enable the ltree extension?
Install it with composer require happenv-com/laravel-ltree, then run the package migration that adds an ltree column to your table. The ltree extension itself must exist in the database, so you need CREATE EXTENSION IF NOT EXISTS ltree, which requires privileges that application migration roles sometimes lack. On managed providers such as RDS, Cloud SQL, Supabase, and Neon it ships in contrib, but confirm it is enabled in every environment including CI containers and ephemeral test databases.
Which Laravel and PHP versions does laravel-ltree support?
The v1.0.0 release artifacts point to a changelog link rather than documented constraints, so the supported Laravel and PHP matrix is not confirmed from the release notes alone. Check composer.json for the actual illuminate/* and php version requirements before adopting, since version constraints are the most common cause of failed installs for packages this young. Then validate the install against your own supported matrix in a short time-boxed spike.
Can I use laravel-ltree with MySQL or SQLite?
No. ltree is a PostgreSQL-specific data type that ships in Postgres contrib, so the package cannot work on MySQL, SQLite, or SQL Server. Adopting it makes PostgreSQL a hard requirement rather than a swappable detail, which matters if your team runs a multi-database test matrix or expects to stay database-portable. If portability is a priority, choose a database-agnostic tree package instead.
How do I query all descendants of a node with ltree in Laravel?
PostgreSQL answers this with the <@ and @> path operators, for example path <@ 'root.category' to fetch the whole subtree, typically wrapped in a query scope the package provides. Confirm the exact scope names in the source before committing, since the package is at v1.0.0 and its API surface is documented thinly. The payoff is that a subtree fetch becomes a single indexed WHERE clause rather than a recursive CTE assembled in PHP.
Do I need a GiST index for ltree ancestor and descendant queries?
In practice yes: path operators such as <@ and @> are only fast with a GiST index on the ltree column, otherwise PostgreSQL falls back to a sequential scan. The release artifacts do not make clear whether the package creates that index for you or leaves it to your migration. Check the package migration and add CREATE INDEX ... USING GIST (path) yourself if it is missing.
How does laravel-ltree handle moving or re-parenting a subtree?
Re-parenting in ltree is a path rewrite, and PostgreSQL handles it with a single UPDATE that concatenates the new path with subpath() of the old one, which is what the package markets as subtree moves. What is unverified is whether the package triggers that recomputation automatically on model events, exposes it as an explicit method, or leaves it entirely to you. Test this early, because stale paths silently corrupt the tree.
What characters can ltree labels contain, and how do I store slugs with hyphens?
ltree labels allow alphanumerics and underscores only, joined by dots, and are length-limited, so slugs with hyphens, UUIDs with dashes, and free-form user text need an encoding scheme such as replacing hyphens with underscores or keeping a human-readable label alongside a separate id column. This is a durable data-model decision rather than a formatting detail, because changing it later means rewriting every stored path. Decide and document the scheme before your first migration.
Is happenv-com/laravel-ltree production-ready?
It is at v1.0.0 with no production track record, a very short issue history, and a small-vendor, possibly single-maintainer profile. There is no visible security disclosure process or stated support policy for the 1.x line, so treat it as a dependency you own rather than one you can lean on. A sensible approach is a time-boxed spike plus a thin internal wrapper so the package can be replaced without touching application code.
What are the alternatives to laravel-ltree for hierarchical data in Laravel?
You can use an adjacency list with parent_id plus recursive CTEs, a nested set package such as kalnoy/nestedset, or a closure table. Each trades differently: adjacency lists are portable but need recursive queries, nested sets make writes expensive and reads cheap, and ltree keeps everything inside PostgreSQL with indexable path operators. If you are already standardized on PostgreSQL, ltree needs the least application-level machinery; if you are not, do not adopt it.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource