laraorvite / eloquent-wildcard-validator
Fixes ErrorException: Indirect modification of overloaded property in Laravel nested validation.
Package info
github.com/LaraOrVite/eloquent-wildcard-validator
pkg:composer/laraorvite/eloquent-wildcard-validator
Requires
- php: ^8.2|^8.3|^8.4|^8.5
- illuminate/support: ^11.0|^12.0|^13.0
- illuminate/validation: ^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^10.0|^11.0
README
This package fixes the ErrorException: Indirect modification of overloaded property that occurs in Laravel when performing wildcard validation on nested data structures containing Eloquent models or objects with magic methods.
The Problem
In Laravel core, when you validate nested data using wildcards (e.g., tickets.*.people.*.email), the validator attempts to initialize missing data. If the data contains Eloquent models, PHP throws an error because magic methods (__get and __set) do not support indirect modification by reference.
The Solution
This package transparently extends the Laravel Validator to ensure that all data is safely converted to a plain array (arrayified) before validation begins, preventing any illegal modification of model properties while preserving the original data integrity.
Installation
You can install the package via composer:
composer require laraorvite/eloquent-wildcard-validator
The package will automatically register its Service Provider.
Usage
No additional configuration is required. Use the Laravel Validator facade or $request->validate() as you normally would:
$data = [ 'orders' => Order::with('items')->get() ]; $request->validate([ 'orders.*.items.*.price' => 'required|numeric' ]);
Credits
- LaraOrVite
- Special thanks to the Laravel community.
License
The MIT License (MIT). Please see License File for more information.