Weave Code
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

Treewalker Laravel Package

lukascivil/treewalker

Lightweight PHP library to traverse and manipulate nested data (arrays, objects, JSON) interchangeably. Includes recursive walker, diffing (new/removed/edited), structure merging, and dynamic get/set helpers. Supports PHP 8.1+.

View on GitHub
Deep Wiki
Context7

TreeWalker is a simple and small Library that will help you to work faster with manipulation of structures in PHP

Frequently asked questions about Treewalker
How do I install TreeWalker in a Laravel project?
Run `composer require lukascivil/treewalker` in your project root. The package requires PHP 8.1+, which aligns with Laravel 9+ and 10+. No additional Laravel-specific setup is needed beyond autoloading.
Can TreeWalker handle deeply nested Eloquent relationships?
Yes, use `getDynamicallyValue()` and `setDynamicallyValue()` to access or modify deeply nested attributes in Eloquent models. For example, update a nested relationship like `$model->setDynamicallyValue('user.address.city', 'New York')`.
What’s the difference between `getdiff()` with `false` vs. `true`?
Passing `false` returns flat slash-delimited keys (e.g., `cafeina/ss`), while `true` returns nested structures. Choose based on whether you need a flattened or hierarchical diff for debugging or automated workflows.
Will TreeWalker work with Laravel’s API resources or Form Request validation?
Yes, use `getdiff()` to compare incoming request data against expected schemas or validate payloads. For example, compare a `FormRequest` payload against a default config structure to detect unauthorized changes.
How does `walker()` handle circular references or malformed JSON?
TreeWalker doesn’t validate input by default, so circular references or invalid JSON may cause errors. Wrap operations in a `try-catch` block or pre-validate data using Laravel’s `json_decode()` with `JSON_THROW_ON_ERROR`.
Can I use TreeWalker to merge Laravel config files dynamically?
Absolutely. Use `structMerge()` to combine environment-specific configs (e.g., `config/merge.php`) with defaults. The first argument takes precedence, which matches Laravel’s config precedence rules.
Does TreeWalker support async operations or Laravel queues?
No, TreeWalker is synchronous. For async use cases (e.g., bulk API updates), dispatch a Laravel job with `walker()` or `getdiff()` and process results in the queue worker.
How do I cache diff results for performance?
Cache diffs using Laravel’s `Cache::remember()`. For example, cache a config diff for 1 hour: `Cache::remember('config_diff', now()->addHours(1), fn() => $treeWalker->getdiff($oldConfig, $newConfig))`.
Are there alternatives for diffing or merging in Laravel?
For diffing, consider `spatie/array-to-xml` or `league/arrayobjects`. For merging, Laravel’s built-in `array_merge_recursive()` or `collect()->merge()` may suffice for simpler cases. TreeWalker excels in handling mixed formats (arrays/objects/JSON) and dynamic paths.
How do I test TreeWalker with Laravel’s Eloquent models?
Write unit tests using PHPUnit to verify dynamic key access. For example, test `getDynamicallyValue()` on a model with nested attributes: `$model->setAttribute('user.address', ['city' => 'Paris']); $this->assertEquals('Paris', $treeWalker->getDynamicallyValue($model, 'user.address.city'))`.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope