Skip to content

Commit

Permalink
Added the isInChannel/isNotInChannel methods to the Channelable trait
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Sep 8, 2023
1 parent 326c5df commit 602b910
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Channel/Traits/Channelable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 602b910

Please sign in to comment.