- How do I install this package in a Laravel project?
- Run `composer require sajadsdi/array-dot-notation` in your project root. The package is dependency-free and integrates instantly with Laravel’s array ecosystem. No configuration or service provider setup is required.
- Does this work with Laravel’s built-in `Arr::dot()` helper?
- Yes, but this package offers a standalone alternative with simpler syntax (e.g., `ArrayDot::set($array, 'a.b', 'value')`). Use it when you need pre-Laravel 5.5 compatibility or prefer a lighter-weight solution without Laravel’s dependencies.
- Can I use dot notation to modify deeply nested arrays in Laravel configs?
- Absolutely. The package supports `set()`, `get()`, and `delete()` operations on nested arrays, making it ideal for Laravel’s `config()` array or `.env`-parsed configurations. Example: `$dotNotation->set('app.debug', true);` updates nested config values.
- Is this package safe for production use in high-traffic Laravel apps?
- Yes, it’s optimized for performance with minimal overhead. Benchmark tests show it handles thousands of dot-notation operations per second, making it suitable for APIs, caching layers, or request payload processing in production.
- How does this handle edge cases like circular references or invalid dot notation (e.g., `a..b`)?
- The package doesn’t validate dot notation syntax (e.g., `a..b` or `a[b]`), which could cause errors. For strict validation, pre-process keys or use Laravel’s `Arr::dot()` alongside it. Circular references may cause infinite loops—test thoroughly in your environment.
- Can I use this to flatten/unflatten arrays for API requests or form data?
- Yes. Use `get()` to extract nested values (e.g., `$dotNotation->get('user.address.city')`) or `set()` to update arrays dynamically. It’s perfect for transforming request payloads or form submissions into dot-notation-friendly structures.
- Does this support default values or callbacks for missing keys?
- Yes. The `get()` method accepts default values (e.g., `$dotNotation->get('user.profile.name', 'Guest')`) and callbacks to conditionally return defaults. Example: `$dotNotation->get('user.profile.name', fn() => 'Anonymous')`.
- How does this compare to `spatie/array-to-object` for Laravel?
- This package focuses solely on dot-notation array manipulation, while `spatie/array-to-object` converts arrays to objects. Use this for lightweight array operations (e.g., configs, requests) and `spatie/array-to-object` if you need object-oriented access.
- Can I make array operations immutable (e.g., return new arrays instead of modifying in-place)?
- No, the package modifies arrays in-place by default. To enforce immutability, wrap operations in `array_merge()` or use `json_decode(json_encode($array), true)` to clone the array before modifications.
- What Laravel versions does this package support, and are there any breaking changes?
- The package is PHP 7.4+ compatible and works with all Laravel versions (5.5+). It’s a standalone utility with no Laravel-specific dependencies, so version updates are risk-free. Check the [GitHub releases](https://github.com/sajadsdi/array-dot-notation/releases) for breaking changes.