ここでLaravelの問題が発生しています。laravel addEagerConstraints on hasOne
私は3つのモデルを持っている:
通知
- ID
- メッセージが...など
参加
- ID
- USER_IDなど
- ..
ユーザ
- ID
- 名
- など。
通知は、参加者テーブルを参照し、両方の送信者(SENDER_ID)と受信者(recipient_id)を有することができます。 参加者にはuser(user_id)への参照があります。
以下のコードで送信者と受信者の両方の通知のリストを取得しようとしています。
public function sender()
{
return $this->hasOne('App\Models\Participant', 'sender_id', 'id')->with(['user']);
}
public function recipient()
{
return $this->hasOne('App\Models\Participant', 'id', 'recipient_id')->with(['user']);
}
これは、空の結果 戻り[関係:保護] =>配列 ( [差出人] => [受信者] => )
にコードを変更:
public function sender()
{
return $this->hasOne('App\Models\Participant', 'sender_id', 'id')->with(['user'])->first();
}
public function recipient()
{
return $this->hasOne('App\Models\Participant', 'id', 'recipient_id')->with(['user'])->first();
}
私は
は、すべての
まず、なぜrecipient()に2つの関数があるのですか? –
間違えて、私は最初の投稿を修正しました。 – quibuz