elasticsearch icon indicating copy to clipboard operation
elasticsearch copied to clipboard

Call to undefined function Basemkhirat\Elasticsearch\array_except()

Open Monica-Ibtikar opened this issue 3 years ago • 2 comments

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

Monica-Ibtikar avatar Dec 30 '20 19:12 Monica-Ibtikar

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"
        ]
    },
...

hrabbit avatar Oct 05 '21 00:10 hrabbit

Hey @hrabbit take a look at matchory/elasticsearch - we're actively maintaining a fork without this issue and support for newer versions :)

Radiergummi avatar Oct 05 '21 08:10 Radiergummi