phrity/util-accessor
Access nested data (arrays, objects, scalars) using simple slash-delimited paths. Provides get() with optional default return and type coercion, plus has() to check if a path exists. Lightweight utility for safe, convenient data retrieval.
get()/set() logic.user.address.city).request->get('user.profile.settings.theme')).user.metrics.avg_score) with DataAccessor for performance.Adopt if:
user.profile.settings.notifications.enabled).isset($data['a']['b']['c']) with $accessor->has($data, 'a/b/c')).Look elsewhere if:
Arr::get()) instead.set().DataAccessor).HasAccessors trait if tightly coupled to Laravel."This package lets us access and manipulate nested data effortlessly—like a Swiss Army knife for arrays, objects, and Eloquent models. Imagine cutting development time by 30% when dealing with complex data structures (e.g., user profiles, API payloads, or form submissions). It’s lightweight, MIT-licensed, and integrates seamlessly with Laravel, so we avoid vendor lock-in while gaining consistency across the codebase. For example, instead of writing 10 lines of nested if checks to validate a user’s address.city.zip, we’d use a single line: $accessor->has($user, 'address/city/zip'). This aligns with our goal to reduce technical debt and accelerate feature delivery."
*"phrity/util-accessor gives us a reusable, type-safe way to handle nested data without reinventing the wheel. Key benefits:
user.profile.settings).Type::STRING or custom transformers via phrity/util-transformer).Accessor: One-off path queries (e.g., $accessor->get($data, 'a/b/c')).PathAccessor: Reuse paths across multiple datasets (e.g., API response templates).DataAccessor: Manage a single dataset with multiple paths (e.g., caching computed attributes).Validator::make($request->all(), ['user.profile.email' => 'required'])).Trade-offs:
set() modifies data in-place (use cautiously in shared contexts).Proposal: Pilot this in the user profile API to replace manual nested access logic. If successful, roll it out to form validation and caching layers."*
How can I help you explore Laravel packages today?