relationship manager on belongs to many with pivot model throws error

I have a following relation on Project::model

public function Members(): BelongsToMany
    {
        return $this->belongsToMany(Member::class)
            ->withPivot('responsibility_id')
            ->using(ProjectMember::class)
            ->with('pivot.responsibility')
            ->leftJoin('responsibilities', 'project_member.responsibility_id', '=', 'responsibilities.id')
            ->orderByPivot('responsibilities.order')
            ->withTimestamps();
    }


when I try to use relation manager I am getting
Call to a member function newCollection() on null error

note that the relationship manager works OK if Member data only from pivot table is gathered (when I comment out pivot additions/ relations)


public function Members(): BelongsToMany
    {
        return $this->belongsToMany(Member::class)
            ->withPivot('responsibility_id')
            // ->using(ProjectMember::class)
            // ->with('pivot.responsibility')
            // ->leftJoin('responsibilities', 'project_member.responsibility_id', '=', 'responsibilities.id')
            // ->orderByPivot('responsibilities.order')
            ->withTimestamps();
    }
Was this page helpful?