elasticsearch
elasticsearch copied to clipboard
Call to undefined function Basemkhirat\Elasticsearch\array_except()
In laravel 8 and php 7.3 when I call save function as written in the docs I get this error Call to undefined function Basemkhirat\Elasticsearch\array_except() in file /home/elasticsearch/elasticsearch-practice/vendor/basemkhirat/elasticsearch/src/Model.php on line 349
I ran across this same issue when implementing this inside Lumen. I didn't wish to butcher the package itself so implemented the array_except function in a local helper.
Not suggesting my logic is the best solution
if (!function_exists('array_except')) {
/**
* Provide array_except helper. This is normally available in Laravel, however, not in Lumen.
* Basemkhirat\Elasticsearch requires this
*
* @param array $array
* @param array $exclude
* @return array
*/
function array_except(array $array, array $exclude)
{
return collect($array)->except($exclude)->toArray();
}
}
Afterwards, I added this helper to my psr files list and rebuilt the autoload.. composer.json
...
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/Helpers/Array.php"
]
},
...
Hey @hrabbit take a look at matchory/elasticsearch - we're actively maintaining a fork without this issue and support for newer versions :)