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

Util Accessor Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Dynamic Data Access Patterns: Enables flexible, path-based access to nested data structures (arrays, objects, Eloquent models) without manual traversal, reducing boilerplate in Laravel applications.
  • Computed Attributes: Supports the roadmap for virtual attributes in Laravel (similar to Eloquent accessors but with deeper nesting support) by providing a reusable foundation for get()/set() logic.
  • Build vs. Buy: Avoids reinventing a custom solution for nested data access, leveraging a lightweight, MIT-licensed package instead of building from scratch.
  • Use Cases:
    • API Response Transformation: Dynamically construct API payloads by accessing nested data via paths (e.g., user.address.city).
    • Form/Validation Logic: Simplify validation rules for deeply nested arrays/objects (e.g., request->get('user.profile.settings.theme')).
    • Caching Strategies: Cache complex, computed paths (e.g., user.metrics.avg_score) with DataAccessor for performance.
    • Legacy System Integration: Standardize access to inconsistent data structures (e.g., migrating from arrays to objects).

When to Consider This Package

  • Adopt if:

    • Your Laravel app frequently accesses nested data (3+ levels deep) across arrays, objects, or Eloquent models.
    • You need type coercion (e.g., converting strings to enums or objects to arrays) during data retrieval.
    • Dynamic path-based access is required for APIs, forms, or validation (e.g., user.profile.settings.notifications.enabled).
    • You’re building a composable data layer (e.g., plugins, modules) where consistent access patterns are critical.
    • Your team prioritizes reducing boilerplate for nested data operations (e.g., replacing isset($data['a']['b']['c']) with $accessor->has($data, 'a/b/c')).
  • Look elsewhere if:

    • Your data is flat (no nesting beyond 1–2 levels). Use Laravel’s built-in array helpers (Arr::get()) instead.
    • You need XPath or JSONPath (this package is a lighter alternative but lacks XPath’s full power).
    • Your use case requires mutability guarantees (e.g., immutable data structures). This package modifies data in-place with set().
    • You’re constrained to PHP < 8.0 (requires PHP 8.1+ for full features like DataAccessor).
    • Your team prefers Laravel-specific solutions (e.g., Eloquent accessors) over generic utilities. Prioritize HasAccessors trait if tightly coupled to Laravel.

How to Pitch It (Stakeholders)

For Executives:

"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."

For Engineers:

*"phrity/util-accessor gives us a reusable, type-safe way to handle nested data without reinventing the wheel. Key benefits:

  • Unified API: Works with arrays, objects, and Eloquent models using the same path syntax (e.g., user.profile.settings).
  • Type Coercion: Convert values on-the-fly (e.g., Type::STRING or custom transformers via phrity/util-transformer).
  • Flexible Patterns:
    • 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).
  • Laravel-Friendly: Plays well with Eloquent, APIs, and validation (e.g., Validator::make($request->all(), ['user.profile.email' => 'required'])).
  • Performance: Minimal overhead; ideal for high-throughput systems.

Trade-offs:

  • Not a drop-in replacement for XPath/JSONPath (but simpler for most use cases).
  • 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."*

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.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky