From 548acc49857099f52864c43a5b5d941a010ef5f0 Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Fri, 20 Dec 2024 12:22:04 +0300 Subject: [PATCH] Show secret code on santa --- app/Models/SecretSantaParticipant.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Models/SecretSantaParticipant.php b/app/Models/SecretSantaParticipant.php index 7f8e1e4b..0bb74892 100644 --- a/app/Models/SecretSantaParticipant.php +++ b/app/Models/SecretSantaParticipant.php @@ -23,6 +23,7 @@ class SecretSantaParticipant extends Model */ protected $with = [ 'receiver', + 'santa' ]; // Связь с пользователем @@ -36,7 +37,15 @@ public function receiver() { return $this ->belongsTo(SecretSantaParticipant::class, 'receiver_id', 'user_id') - ->without('receiver'); + ->without('receiver', 'santa'); + } + + // Связь с Сантой (кто отправляет мне подарок) + public function santa() + { + return $this + ->hasOne(SecretSantaParticipant::class, 'receiver_id', 'user_id') + ->without('receiver', 'santa'); } /** @@ -46,4 +55,14 @@ public function hasReceiver(): bool { return $this->receiver_id !== null; } + + /** + * Проверяет, есть ли у пользователя Санта + * + * @return bool + */ + public function hasSanta(): bool + { + return $this->santa !== null; + } }