From 602b9109b2d689dbbdb9634ba93daaf319190b02 Mon Sep 17 00:00:00 2001 From: Attila Fulop <1162360+fulopattila122@users.noreply.github.com> Date: Fri, 8 Sep 2023 12:55:22 +0300 Subject: [PATCH] Added the isInChannel/isNotInChannel methods to the Channelable trait --- src/Channel/Traits/Channelable.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Channel/Traits/Channelable.php b/src/Channel/Traits/Channelable.php index ef30d51a..4577757f 100644 --- a/src/Channel/Traits/Channelable.php +++ b/src/Channel/Traits/Channelable.php @@ -14,13 +14,28 @@ namespace Vanilo\Channel\Traits; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Vanilo\Channel\Contracts\Channel; use Vanilo\Channel\Models\ChannelProxy; +/** + * @property-read Collection $channels + */ trait Channelable { public function channels(): MorphToMany { return $this->morphToMany(ChannelProxy::modelClass(), 'channelable'); } + + public function isInChannel(Channel|int|string $channel): bool + { + return $this->channels->contains($channel); + } + + public function isNotInChannel(Channel|int|string $channel): bool + { + return !$this->isInChannel($channel); + } }