Skip to content

Commit 602b910

Browse files
Added the isInChannel/isNotInChannel methods to the Channelable trait
1 parent 326c5df commit 602b910

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Channel/Traits/Channelable.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,28 @@
1414

1515
namespace Vanilo\Channel\Traits;
1616

17+
use Illuminate\Database\Eloquent\Collection;
1718
use Illuminate\Database\Eloquent\Relations\MorphToMany;
19+
use Vanilo\Channel\Contracts\Channel;
1820
use Vanilo\Channel\Models\ChannelProxy;
1921

22+
/**
23+
* @property-read Collection $channels
24+
*/
2025
trait Channelable
2126
{
2227
public function channels(): MorphToMany
2328
{
2429
return $this->morphToMany(ChannelProxy::modelClass(), 'channelable');
2530
}
31+
32+
public function isInChannel(Channel|int|string $channel): bool
33+
{
34+
return $this->channels->contains($channel);
35+
}
36+
37+
public function isNotInChannel(Channel|int|string $channel): bool
38+
{
39+
return !$this->isInChannel($channel);
40+
}
2641
}

0 commit comments

Comments
 (0)