Skip to content

Commit

Permalink
✨ Add check for a particular plan
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardojbaez committed Sep 28, 2016
1 parent 5c6f5de commit eb0e0f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ For a subscription to be considered active _one of the following must be `true`_

```php
$user->subscribed('main');
$user->subscribed('main', $planId); // Check if user is using a particular plan
```

Alternatively you can use the following methods available in the subscription model:
Expand Down
11 changes: 9 additions & 2 deletions src/LaraPlans/Traits/PlanSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,23 @@ public function subscriptions()
* Check if the user has a given subscription.
*
* @param string $subscription
* @param int $planId
* @return bool
*/
public function subscribed($subscription = 'default')
public function subscribed($subscription = 'default', $planId = null)
{
$subscription = $this->subscription($subscription);

if (is_null($subscription))
return false;

return $subscription->active();
if (is_null($planId))
return $subscription->active();

if ($planId == $subscription->plan_id AND $subscription->active())
return true;

return false;
}

/**
Expand Down

0 comments on commit eb0e0f9

Please sign in to comment.