I have a form full of nested values that are handled as arrays and I'm trying to validate it properly using Laravel's bult-in validation. I keep running into an Error Exception about htmlentities receiving an array instead of string on the e() function. As far as I can tell this happens when all the validation is done and the framework is trying to repopulate my form for the returned view with errors:
if (!function_exists('e')) {
/**
* Escape HTML entities in a string.
*
* @param \Illuminate\Support\Htmlable|string $value
* @return string
*/
function e($value)
{
if ($value instanceof Htmlable) {
return $value->toHtml();
}
return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
}
}
Where should I put my own e() function so that it will be read before this one?
Thanks @mul14 I went temporarily down the route of changing bootstrap/autoload.php and it's working fine. But isn't that going to be wiped when I update laravel?
Your second solution is cleaner but won't help me. I need to redefine e() so that the Validator can use my function instead of the one defined in helpers.php. That's why namespacing is not an option, unfortunately.
It's ok. When you update the Laravel by doing composer update, the composer will replace/update vendor/laravel folder. The other folders will not affects.
First apologies for necroposting. But I ran into this problem recently and the bootstrap/autoload.php method doesn't work if you're using PHPUnit. I figured I'd share my solution for posterity sake.