From eb0e0f95fa3c7f6f9e33d9167bd6690022245982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerardo=20B=C3=A1ez?= Date: Wed, 28 Sep 2016 14:30:22 -0400 Subject: [PATCH] :sparkles: Add check for a particular plan --- README.md | 1 + src/LaraPlans/Traits/PlanSubscriber.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fa903cd..32265b0 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/LaraPlans/Traits/PlanSubscriber.php b/src/LaraPlans/Traits/PlanSubscriber.php index b316aaf..2984cc7 100644 --- a/src/LaraPlans/Traits/PlanSubscriber.php +++ b/src/LaraPlans/Traits/PlanSubscriber.php @@ -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; } /**