When $model->newCollection($results['ids']) we have a correct collection with IDs in it (based on models newCollection() method). Our custom collection is extending EloquentCollection where you will call ->map() on. The map() function of the EloquentCollection is implemented as follows:
So the problem is that EloquentCollection uses ->toBase() which converts it back to \Support\Illumate\Collection, because in the collection we only have numbers and these are not instanceof Model.
Potential solution
Use $model->newCollection() on the final result as follows:
return $model->newCollection(collect($results['ids'])->map(function ($hit) use ($models) {
if (isset($models[$hit])) {
return $models[$hit];
}
})->filter()->all());
The PR that fixes these issue will follow in the next minutes.
Problem
As I already described in https://github.com/teamtnt/laravel-scout-tntsearch-driver/issues/338 we have now the same problem with a matched result.
The problem is used to be here: https://github.com/teamtnt/laravel-scout-tntsearch-driver/blob/b98729b0c7179218c9a5e1445922a9313d45c487/src/Engines/TNTSearchEngine.php#L221-L225
When
$model->newCollection($results['ids'])
we have a correct collection with IDs in it (based on modelsnewCollection()
method). Our custom collection is extendingEloquentCollection
where you will call->map()
on. Themap()
function of theEloquentCollection
is implemented as follows:So the problem is that
EloquentCollection
uses->toBase()
which converts it back to\Support\Illumate\Collection
, because in the collection we only have numbers and these are notinstanceof Model
.Potential solution
Use $model->newCollection() on the final result as follows:
The PR that fixes these issue will follow in the next minutes.