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

Vale Laravel Package

cocur/vale

cocur/vale is a lightweight PHP value validation library. Define reusable rules to validate strings, numbers, arrays, and objects, and get clear, consistent results without pulling in a full framework—handy for DTOs, APIs, and input sanitization.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing via Composer (composer require cocur/vale) and importing the Vale class—this package is intentionally minimal, offering just a single static interface. Your first use case is likely safely reading deeply nested data: Vale::get($array, 'user.profile.address.city') returns null if any level is missing, avoiding undefined index errors. Check existence with Vale::exists($data, 'user.settings.theme') before using values—perfect for handling inconsistent API responses or config arrays.

Implementation Patterns

Use Vale::set() to update nested values in-place on arrays or objects (supports dot notation), e.g., Vale::set($config, 'database.connections.mysql.host', '127.0.0.1'). Chain operations like Vale::get() and Vale::exists() in validation logic—e.g., verifying optional nested form fields before saving. For transformations, combine with array_map or closures: Vale::set($data, 'items', array_map('strtolower', Vale::get($data, 'items') ?? [])). Works seamlessly with Laravel’s collect()—extract nested values using Vale for complex structures before pushing data into Eloquent models.

Gotchas and Tips

The package hasn’t been updated since 2015—ensure compatibility with PHP 8+ by testing edge cases (e.g., stringable objects or strict scalar comparisons). Vale does not handle arrays of objects automatically: Vale::get($data, 'users.0.name') requires users[0] to be an array; mix with ArrayAccess wrappers for mixed object/array trees. Debug failures by enabling E_ALL & ~E_DEPRECATED—older PHP warnings may surface around create_function() (used internally), though not active in PHP 7.2+. Consider wrapping Vale in a custom helper (e.g., vale_get()) to add logging or fallback logic. If migrating to modern alternatives, evaluate symfony/property-access for richer object graph support—but Vale remains excellent for lightweight, flat dot-notation on arrays.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4