Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to undefined function Basemkhirat\Elasticsearch\array_except() #123

Open
Monica-Ibtikar opened this issue Dec 30, 2020 · 2 comments
Open

Comments

@Monica-Ibtikar
Copy link

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

@hrabbit
Copy link

hrabbit commented Oct 5, 2021

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

@Radiergummi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants