Skip to content

Commit

Permalink
chore: remove check use trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ducconit committed Aug 13, 2024
1 parent 4e0dd6d commit 874d5cb
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 32 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "overtrue/laravel-follow",
"name": "sphoton/laravel-follow",
"description": "User follow unfollow system for Laravel.",
"license": "MIT",
"authors": [
Expand Down
12 changes: 0 additions & 12 deletions src/Traits/Followable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,16 @@ public function needsToApproveFollowRequests(): bool

public function rejectFollowRequestFrom(Model $follower): void
{
if (! in_array(Follower::class, \class_uses($follower))) {
throw new \InvalidArgumentException('The model must use the Follower trait.');
}

$this->followables()->followedBy($follower)->get()->each->delete();
}

public function acceptFollowRequestFrom(Model $follower): void
{
if (! in_array(Follower::class, \class_uses($follower))) {
throw new \InvalidArgumentException('The model must use the Follower trait.');
}

$this->followables()->followedBy($follower)->get()->each->update(['accepted_at' => \now()]);
}

public function isFollowedBy(Model $follower): bool
{
if (! in_array(Follower::class, \class_uses($follower))) {
throw new \InvalidArgumentException('The model must use the Follower trait.');
}

if ($this->relationLoaded('followables')) {
return $this->followables->whereNotNull('accepted_at')->contains($follower);
}
Expand Down
20 changes: 1 addition & 19 deletions src/Traits/Follower.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Overtrue\LaravelFollow\Traits;

use function abort_if;
use function class_uses;
use function collect;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Collection;
Expand All @@ -13,7 +12,6 @@
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Enumerable;
use Illuminate\Support\LazyCollection;
use function in_array;
use InvalidArgumentException;
use function is_array;
use function iterator_to_array;
Expand All @@ -31,10 +29,6 @@ public function follow(Model $followable): array
throw new InvalidArgumentException('Cannot follow yourself.');
}

if (! in_array(Followable::class, class_uses($followable))) {
throw new InvalidArgumentException('The followable model must use the Followable trait.');
}

/** @var \Illuminate\Database\Eloquent\Model|\Overtrue\LaravelFollow\Traits\Followable $followable */
$isPending = $followable->needsToApproveFollowRequests() ?: false;

Expand All @@ -50,10 +44,6 @@ public function follow(Model $followable): array

public function unfollow(Model $followable): void
{
if (! in_array(Followable::class, class_uses($followable))) {
throw new InvalidArgumentException('The followable model must use the Followable trait.');
}

$this->followings()->of($followable)->get()->each->delete();
}

Expand All @@ -64,10 +54,6 @@ public function toggleFollow(Model $followable): void

public function isFollowing(Model $followable): bool
{
if (! in_array(Followable::class, class_uses($followable))) {
throw new InvalidArgumentException('The followable model must use the Followable trait.');
}

if ($this->relationLoaded('followings')) {
return $this->followings
->whereNotNull('accepted_at')
Expand All @@ -81,10 +67,6 @@ public function isFollowing(Model $followable): bool

public function hasRequestedToFollow(Model $followable): bool
{
if (! in_array(\Overtrue\LaravelFollow\Traits\Followable::class, \class_uses($followable))) {
throw new InvalidArgumentException('The followable model must use the Followable trait.');
}

if ($this->relationLoaded('followings')) {
return $this->followings->whereNull('accepted_at')
->where('followable_id', $followable->getKey())
Expand Down Expand Up @@ -149,7 +131,7 @@ public function attachFollowStatus($followables, callable $resolver = null)
$resolver = $resolver ?? fn ($m) => $m;
$followable = $resolver($followable);

if ($followable && in_array(Followable::class, class_uses($followable))) {
if ($followable) {
$item = $followed->where('followable_id', $followable->getKey())
->where('followable_type', $followable->getMorphClass())
->first();
Expand Down

0 comments on commit 874d5cb

Please sign in to comment.