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
Property Access

Property Access Laravel Package

symfony/property-access

Symfony PropertyAccess reads and writes object and array values using simple string notation such as "user.address.street". It handles getters, setters, public properties, ArrayAccess, and magic methods, making nested data access generic and consistent across forms, serializers, and valida...

View on GitHub
Deep Wiki
Context7

PropertyAccess provides a simple, consistent API for reading and writing values from objects and arrays using a compact string notation such as person.address.street. It transparently handles getters, setters, public properties, magic methods, and array keys, so your code stays decoupled from the underlying data structure.

This makes it ideal for form handling, serialization, validation, and any dynamic data mapping where the path is known only at runtime.

  • Read/write nested paths with dot notation and array indices
  • Supports getters/setters, public properties, __get/__set, and ArrayAccess
  • Null-safe operator (?) to safely traverse missing values
  • isReadable() / isWritable() checks with precise exceptions
  • Configurable behavior via PropertyAccessorBuilder
Frequently asked questions about Property Access
How do I install Symfony PropertyAccess in a Laravel project?
Run `composer require symfony/property-access` in your project root. No additional Laravel-specific setup is needed, though you may wrap it in a facade (e.g., `PropertyAccess::getValue()`) for cleaner syntax. The package integrates seamlessly with Laravel’s service container.
Can I use this for Eloquent model attribute access?
While possible, Eloquent’s native accessors (e.g., `$model->attribute`) are preferred for database models. PropertyAccess shines with non-ORM objects like DTOs, API payloads, or complex nested arrays where string paths (e.g., `'user.address.city'`) simplify traversal.
What Laravel versions does this package support?
Symfony PropertyAccess works with Laravel 8+ (PHP 8.1+) and is future-proof for PHP 8.4+. For older Laravel versions, pin to `^6.4` for PHP 8.1+ support. No Laravel-specific versioning exists—it’s a standalone Symfony component.
Will this break existing `Arr::get()` or `data_get()` usage?
No. PropertyAccess extends dynamic access to *objects* while Laravel’s `Arr::get()` handles arrays. Use both tools in tandem: `Arr::get()` for arrays, PropertyAccess for objects/DTOs. Migration is incremental—start with new features and toggle old logic via feature flags.
How does performance compare to manual getters/setters?
PropertyAccess adds ~10–20% overhead in hot paths due to reflection. For performance-critical APIs, cache reflection metadata (Symfony does this internally) or stick to manual getters. Benchmark against your current traversal logic before adoption.
Can I restrict access to sensitive properties (e.g., passwords)?
Yes. Use Symfony’s built-in configuration to whitelist/blacklist paths or extend the accessor to validate paths against a ruleset. For Laravel, create a custom facade method like `PropertyAccess::safeGet($path, $object)` to enforce security.
How does this integrate with Laravel’s validation or form requests?
PropertyAccess simplifies nested validation by replacing manual traversal (e.g., `$request->input('user.address.city')`) with string paths. In Form Requests, use `PropertyAccess::getValue($request->all(), 'user.address.city')` to dynamically map input to objects.
Are there alternatives for Laravel-specific property access?
Laravel’s `Arr::get()` handles arrays, and Eloquent provides model accessors. For objects/DTOs, alternatives include manual getters, Reflection, or packages like `spatie/array-to-object`. PropertyAccess stands out for its Symfony-backed robustness, nested path support, and integration with other Symfony components.
How do I handle circular references or private properties?
Symfony PropertyAccess throws exceptions by default for circular references. Configure it to ignore or handle them via `PropertyAccessBuilder::enableExceptionOnInvalidIndex(false)`. For private properties, use `PropertyAccessBuilder::enableMagicAccess(true)` or extend the accessor with custom logic.
What’s the best way to test PropertyAccess in Laravel?
Test edge cases like nested paths, invalid properties, and circular references. Mock the accessor in unit tests (e.g., `PropertyAccess::getValue()`) and verify output matches expected DTOs or arrays. Leverage Symfony’s existing ~90% test coverage as a reference for your test suite.
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.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo