Skip to content

Commit

Permalink
change name class
Browse files Browse the repository at this point in the history
  • Loading branch information
dapehe94 committed Oct 24, 2023
1 parent a6c4fe9 commit 6c3034e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Traits/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Support\LazyCollection;

/**
* @property \Illuminate\Database\Eloquent\Collection $subscriptions
* @property \Illuminate\Database\Eloquent\Collection $subscribes
*/
trait Subscriber
{
Expand All @@ -23,7 +23,7 @@ public function subscribe(Model $object)
$subscribe->subscribable_id = $object->getKey();
$subscribe->subscribable_type = $object->getMorphClass();

$this->subscriptions()->save($subscribe);
$this->subscribes()->save($subscribe);
}
}

Expand All @@ -33,7 +33,7 @@ public function subscribe(Model $object)
public function unsubscribe(Model $object)
{
/* @var \Dapehe94\LaravelSubscribe\Traits\Subscribable|Model $object */
$relation = $this->subscriptions()
$relation = $this->subscribes()
->where('subscribable_id', $object->getKey())
->where('subscribable_type', $object->getMorphClass())
->where(config('subscribe.user_foreign_key'), $this->getKey())
Expand All @@ -54,7 +54,7 @@ public function toggleSubscribe(Model $object)

public function hasSubscribed(Model $object): bool
{
return tap($this->relationLoaded('subscriptions') ? $this->subscriptions : $this->subscriptions())
return tap($this->relationLoaded('subscribes') ? $this->subscribes : $this->subscribes())
->where('subscribable_id', $object->getKey())
->where('subscribable_type', $object->getMorphClass())
->count() > 0;
Expand Down Expand Up @@ -86,7 +86,7 @@ public function attachSubscriptionStatus($subscribables, callable $resolver = nu

\abort_if(! ($subscribables instanceof Enumerable), 422, 'Invalid $subscribables type.');

$subscribed = $this->subscriptions()->get();
$subscribed = $this->subscribes()->get();

$subscribables->map(
function ($subscribable) use ($subscribed, $resolver) {
Expand All @@ -107,7 +107,7 @@ function ($subscribable) use ($subscribed, $resolver) {
return $returnFirst ? $subscribables->first() : $subscribables;
}

public function subscriptions(): \Illuminate\Database\Eloquent\Relations\HasMany
public function subscribes(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(config('subscribe.subscription_model'), config('subscribe.user_foreign_key'), $this->getKeyName());
}
Expand Down

0 comments on commit 6c3034e

Please sign in to comment.