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

[6.1.3] Method Illuminate\Support\Collection::load does not exist. #339

Closed
Dylan-Chapman opened this issue Dec 20, 2018 · 8 comments
Closed

Comments

@Dylan-Chapman
Copy link

When I updated to 6.1.3 from 6.1.1, I can no longer do the following:

MyModel::search('myQuery')->get()->load('myRelation');

And I receive the error

Method Illuminate\Support\Collection::load does not exist.

Is there a new suggested method for loading relationships with searching?

@driesvints
Copy link
Member

You're getting back a plain collection instead of an Illuminate\Database\Eloquent\Collection. It could be due to the changes made in #334 but I'm not so sure why you're getting back a plain collection.

Are you overwriting the newCollection method in your model? Are you using the query method on the Scout Builder?

@Dylan-Chapman
Copy link
Author

Nope, not overwriting newCollection, and not sure what the query method on the Scout Builder is/does. My model uses Laravel\Scout\Searchable and has a toSearchableArray method, and a controller that returns the results of MyModel::search('myQuery')->get()->load('myRelation');. That's all that's really happening related to searching.

If it matters, I'm using the teamtnt/laravel-scout-tntsearch-driver search driver.

@Dylan-Chapman
Copy link
Author

Oh, I'd like to add that I can get around the problem by doing the following instead:

MyModel::search('myQuery')->paginate(0)->load('myRelation');

@driesvints
Copy link
Member

I think it might be related to this piece of code: https://github.com/teamtnt/laravel-scout-tntsearch-driver/blob/master/src/Engines/TNTSearchEngine.php#L197-L206

But it's best that you open up an issue on their repo.

@sanjayojha
Copy link

I have the same problem. I am using it with Laravel 5.7 and latest drivers.
For now, I am using the temp fix suggested by @Dylan-Chapman

$posts = Post::search($query)->where('approved', 1)->paginate(0);
$posts->load(['author', 'category']);

Any update on it?

@mforcer
Copy link

mforcer commented Jun 23, 2019

@driesvints is this a TNT issue? The problem that I can see is that when using search() on a model it returns a Laravel\Scout\Builder instance which does not have access to load/with and neither does Collections obviously meaning neither of the relation loading methods can be used when returning results.

I've been forced to use the paginate(0) method to get around it.

@driesvints
Copy link
Member

@mforcer I believe so. Look at the line I linked to. It always returns a plain collection and not an Eloquent one.

@alchibekov
Copy link

alchibekov commented Aug 5, 2021

Oh, I'd like to add that I can get around the problem by doing the following instead:

MyModel::search('myQuery')->paginate(0)->load('myRelation');
MyModel::search('myQuery')->get()->load('myRelation');

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

No branches or pull requests

5 participants