Laravel-mongodb: $withCount return Illegal offset type

Created on 26 Jan 2018  路  3Comments  路  Source: jenssegers/laravel-mongodb

I get the Illegal offset type error with protected $withCount = ['replies'] or Post::withCount('replies').

Any fix soon?

duplicate question

Most helpful comment

Please reopen this issue the workaround by making it an accessor will not help eager loading.

withCount should be the proper way to do this.

All 3 comments

Solved by Appending and Accessor

protected $appends = ['RepliesCount'];

public function getRepliesCountAttribute() { return $this->replies->count(); }

Please reopen this issue the workaround by making it an accessor will not help eager loading.

withCount should be the proper way to do this.

@alexjose done.

Was this page helpful?
0 / 5 - 0 ratings