Laravel: hasMany relationship with multiple foreign keys?

Viewed 89

I currently have a relationship like so,

public function transactions() {
    return $this->hasMany(UserTransaction::class, 'creator_id', 'id')->orderBy('created_at', 'DESC');
}

How can I fetch where UserTransaction.creator_id is equal to User.id, but also records where UserTransaction.target_id might be equal to User.id. Records will only ever be either, a user will never fill creator_id AND target_id.

0 Answers
Related