Skip to content

a little help understanding the Likable trait #11

@jayenne

Description

@jayenne

I've added parent_id to tweets as a means to include tweets as comments too.
I've added a parent() and children() method to the Tweet model

    public function children()
    {
        return $this->hasMany('App\Tweet', 'parent_id')->with('children');
    }

But when I add ->withCount('children') to the timeline() method it foobar's the ->withLikes() method. instead of a number for likes & dislikes I get json string of the likes array instead.
[{"id":1,"user_id":1,"tweet_id":50,"liked":1,"created_at":"2020-10-12T20:24:10.000000Z","updated_at":"2020-10-12T20:27:00.000000Z"},{"id":3,"user_id":2,"tweet_id":50,"liked":1,"created_at":"2020-10-12T20:24:29.000000Z","updated_at":"2020-10-12T20:24:29.000000Z"}]

My questions is, why does this happen? is it someinthg in the Likable trait that doesn't like the withCount or the possiblitiy is nesting? or other?

I know and appreiacite it is a little off-topic so any help would be cool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions