Elasticquent icon indicating copy to clipboard operation
Elasticquent copied to clipboard

When i call $model->addToIndex();

Open sfdsfdsfdesfdsghefasefs opened this issue 6 years ago • 5 comments

BadMethodCallException Method Illuminate\Database\Eloquent\Collection::addToIndex does not exist.

sfdsfdsfdesfdsghefasefs avatar Oct 30 '18 05:10 sfdsfdsfdesfdsghefasefs

Seems like you're calling addToIndex() on a Collection (of models, presumably) not on a single Model.

d1am0nd avatar Nov 05 '18 22:11 d1am0nd

Seems like you're calling addToIndex() on a Collection (of models, presumably) not on a single Model.

I have same error, in the docs say its possible...

You can also index a collection of models:

    $books = Book::where('id', '<', 200)->get();
    $books->addToIndex();

maganius avatar Dec 06 '18 19:12 maganius

Extend ElasticquentCollection or add "use ElasticquentCollectionTrait;" to your Eloquent models

coffeeburrito avatar Dec 06 '18 19:12 coffeeburrito

Hi I have the same problem

use Illuminate\Database\Eloquent\Model; use Elasticquent\ElasticquentTrait;

class wear extends Model { use ElasticquentTrait;

BadMethodCallException : Method Elasticquent\ElasticquentCollection::addAllToIndex does not exist.

Olegars avatar Jan 14 '19 00:01 Olegars

@Olegars, your code doesn't match the error. Your sample shows "ElasticquentTrait", but the error shows "ElasticquentCollection".

Regardless, note that ElasticquentCollectionTrait has "addToIndex()", while ElasticquentTrait has "addAllToIndex()".

coffeeburrito avatar Jan 16 '19 13:01 coffeeburrito