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

Tree Laravel Package

nicmart/tree

A flexible PHP tree data structure with a fluent builder API. Create nodes with any value, add or remove children, manage parents automatically, and build hierarchies easily for menus, categories, and nested data.

View on GitHub
Deep Wiki
Context7

A basic but flexible php tree data structure and a fluent tree builder implementation.

Frequently asked questions about Tree
What is nicmart/tree used for in Laravel applications?
nicmart/tree provides a basic but flexible in-memory tree data structure for PHP, with NodeInterface and Node implementations for parent and child management. In Laravel it is best used as a service layer for hierarchical domains such as menus, categories, or permission trees while Eloquent handles persistence. It is framework-agnostic, so Laravel integration is optional and usually wrapped in your own service class.
How do I install nicmart/tree with Composer in Laravel?
Run composer require nicmart/tree in your Laravel project. The package does not register a Laravel service provider or facade because it is framework-agnostic. Instantiate Tree\Node\Node or the fluent builder classes directly, or bind them inside a small Laravel service class.
Does nicmart/tree support Laravel 10 or Laravel 11?
The package does not publish an official Laravel version matrix. Because it is framework-agnostic, it can run on Laravel releases whose PHP requirement matches the package's PHP 8.0+ baseline; Laravel 10 requires PHP 8.1+, so verify Composer constraints before installing. Test against your target Laravel version before relying on it.
How do I build a tree with the fluent builder in nicmart/tree?
Use Tree\Node\Node and chain addChild calls, or use the included fluent builder classes to assemble trees. The README shows setting node values, adding and removing children, replacing the children set, and checking isLeaf or isChild. For maintainability, wrap builder usage in a Laravel service rather than calling package APIs throughout your application.
Can nicmart/tree convert a tree to an array for Eloquent models?
The package includes array conversion utilities, and the technical assessment notes they simplify data binding with Eloquent models. A practical approach is to transform Eloquent collections into node values and rebuild the in-memory tree for traversal. Keep persistence in Eloquent and use the package only for tree logic and array output.
Is nicmart/tree safe for production use in a Laravel app?
Use caution for critical data integrity operations. The assessment flags limited visible maintenance activity, no public issue tracker, and license or source provenance concerns, so avoid making it the sole authority for transactional tree writes. It is better suited to non-critical operations such as read-only traversal or menu rendering, with a wrapper class that lets you replace it later.
How should I test nicmart/tree in a Laravel project?
Write unit tests around your own TreeService wrapper instead of depending only on package internals. The README shows CI and coverage badges, but the assessment notes no detailed test coverage documentation, so cover edge cases such as empty children, reparenting, removal, and custom value types. Use Laravel's testing tools with in-memory nodes and assert the resulting arrays or traversals.
What are alternatives to nicmart/tree for hierarchical data in Laravel?
For Eloquent-backed hierarchical data, consider laravel-nestedset or a custom adjacency-list implementation with recursive queries. nicmart/tree is generic and does not handle database persistence, so it complements rather than replaces Eloquent tree packages. Choose based on whether you need in-memory traversal, database querying, or both.
Does nicmart/tree support custom node value types and PHP 8?
The package has moved toward a generic node value type, allowing custom PHP values rather than only strings. That aligns with PHP 8.0+ practices but can add type-handling complexity in Laravel typed properties. Verify the installed version's API and cast values explicitly when binding nodes to Eloquent models.
How do I handle persistence and large trees with nicmart/tree?
Keep persistence separate: load records through Eloquent, build an in-memory nicmart/tree structure, traverse or modify it, then persist changes through Eloquent hooks. For trees above roughly 10k nodes, benchmark memory and recursion behavior because the assessment notes that generic type overhead may affect large data sets. Avoid critical write operations until maintenance activity is confirmed.
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.
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle