Eloquent关系。与不同的键有很多关系

Eloquent Relationship. Has Many relation with different keys

背景

我有一个模型,Contract 通过两个键 user_idrecipient_id 属于 User 模型。我如何才能使用 $user->contracts 查询用户的所有合同,同时考虑这两个键。

\App\Contract 型号有这个

$protected $fillable = [
   ...
   'user_id',
   'recipient_id',
   ...
];

public function user ()
{
   return $this->belongsTo(User::class);
}
public function recipient()
{
   return $this->belongsTo(User::class, 'recipient_id', 'id');
}

\App\User 型号有这个

public function contracts ()
{
  return $this->hasMany(Contract::class);
}

要获得用户合同,我必须这样做

$contracts = Contract::where('user_id', $user->id)
   ->orWhere('recipient_id', $user->id)
   ->get();

我想要的是这样的东西。 \App\Contract

public function user () {
  return $this->belongsTo([User::class, User::class], ['user_id', 'recipient_id']);
}

我知道 https://github.com/staudenmeir/eloquent-has-many-deep 但它没有解决我的问题。

我该怎么做?

我找不到办法,所以,我在 ContractController.php

结束了这件事
public function index()
    {
        $user = Auth::user();

        if ($user->isAdmin()) {
            return Contract::latest()->get();
        }

        $contracts = Contract::where('user_id', $user->id)
            ->orWhere('recipient_id', $user->id)
            ->get();

        return $contracts;
    }