Answer the question
In order to leave comments, you need to log in
Is eager loading not compatible with custom collections in laravel?
If the model is eager loaded
public function companies()
{
$this->load('contacts.companies')
// ...
}
public function newCollection(array $models = array())
{
return new ContactCollection($models);
}
Type error: Argument 2 passed to Illuminate\Database\Eloquent\Relations\BelongsToMany::match() must be an instance of Illuminate\Database\Eloquent\Collection, instance of App\Collections\ContactCollection given, called in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php on line 678
Answer the question
In order to leave comments, you need to log in
You need to inherit ContactCollection
from Illuminate\Database\Eloquent\Collection
. Most likely, you are Illuminate\Support\Collection
inherited from or not inherited at all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question