When I try to lazy eager load by using this construct $posts->load('author')
, using a custom collection object, I get the error saying that the collection object does not have the method load
.
Post Model:
class Post extends Eloquent
{
public function newCollection(array $models = array())
{
return new CustomCollection( $models );
}
}
CustomCollection
class CustomCollection extends Illuminate\Support\Collection
{
public function specialCollectionMethod()
{
return 'something that a standard collection does not provide';
}
}
I realized what I was doing wrong but already wrote the post (above) so I thought I'd fix my mistake:
I realized I need to extend Illuminate\Database\Eloquent\Collection
rather than Illuminate\Database\Eloquent\Collection
in my CustomCollection. I misread the documentation.
CustomCollection
class CustomCollection extends Illuminate\Database\Eloquent\Collection
{
public function specialCollectionMethod()
{
return 'something that a standard collection does not provide';
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With