From b7c8640bc32cceeef96dcc1b6dda16f892361287 Mon Sep 17 00:00:00 2001 From: Stefano Kowalke Date: Tue, 18 Apr 2017 23:14:16 +0200 Subject: [PATCH 1/5] Fix the @return value Change Subscription to PlanSubscription --- src/LaraPlans/Traits/PlanSubscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LaraPlans/Traits/PlanSubscriber.php b/src/LaraPlans/Traits/PlanSubscriber.php index ae5ad7d..336a3ae 100644 --- a/src/LaraPlans/Traits/PlanSubscriber.php +++ b/src/LaraPlans/Traits/PlanSubscriber.php @@ -15,7 +15,7 @@ trait PlanSubscriber * Get a subscription by name. * * @param string $name - * @return \Gerardojbaez\LaraPlans\Models\Subscription|null + * @return \Gerardojbaez\LaraPlans\Models\PlanSubscription|null */ public function subscription($name = 'default') { From 19d7a08fec08f4ec578fea1827cb8ec8303baf4c Mon Sep 17 00:00:00 2001 From: Stefano Kowalke Date: Wed, 19 Apr 2017 12:14:42 +0200 Subject: [PATCH 2/5] Get a plan feature by its code See #3 --- README.md | 8 ++++++++ src/LaraPlans/Models/Plan.php | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 824b262..39ad6db 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,14 @@ $plan->features()->saveMany([ ]); ``` +### Get the value of Feature + +Say you want to show the value of the feature _pictures_per_listing_ from above. You can use `getFeatureByCode()`. + +```php +$amountOfPictures = $plan->getFeatureByCode('pictures_per_listing')->value +``` + ### Creating subscriptions You can subscribe a user to a plan by using the `newSubscription()` function available in the `PlanSubscriber` trait. First, retrieve an instance of your subscriber model, which typically will be your user model and an instance of the plan your user is subscribing to. Once you have retrieved the model instance, you may use the `newSubscription` method to create the model's subscription. diff --git a/src/LaraPlans/Models/Plan.php b/src/LaraPlans/Models/Plan.php index 35886f7..6ec231e 100644 --- a/src/LaraPlans/Models/Plan.php +++ b/src/LaraPlans/Models/Plan.php @@ -2,6 +2,7 @@ namespace Gerardojbaez\LaraPlans\Models; +use Gerardojbaez\LaraPlans\Exceptions\InvalidPlanFeatureException; use Gerardojbaez\LaraPlans\Period; use Illuminate\Database\Eloquent\Model; use Gerardojbaez\LaraPlans\Contracts\PlanInterface; @@ -112,4 +113,24 @@ public function hasTrial() { return (is_numeric($this->trial_period_days) and $this->trial_period_days > 0); } + + /** + * Returns the demanded feature + * + * @param String $code + * @return PlanFeature + * @throws InvalidPlanFeatureException + */ + public function getFeatureByCode($code) + { + $feature = $this->features()->getEager()->first(function($item) use ($code) { + return $item->code === $code; + }); + + if (is_null($feature)) { + throw new InvalidPlanFeatureException($code); + } + + return $feature; + } } From 55e068e9017c2728ca90d15f9708f1ac750def8c Mon Sep 17 00:00:00 2001 From: Stefano Kowalke Date: Wed, 19 Apr 2017 12:47:23 +0200 Subject: [PATCH 3/5] Fix the @return values --- src/LaraPlans/SubscriptionUsageManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LaraPlans/SubscriptionUsageManager.php b/src/LaraPlans/SubscriptionUsageManager.php index 3a8c8e3..20613af 100644 --- a/src/LaraPlans/SubscriptionUsageManager.php +++ b/src/LaraPlans/SubscriptionUsageManager.php @@ -7,14 +7,14 @@ class SubscriptionUsageManager /** * Subscription model instance. * - * @var \Illuminate\Database\Eloqunet\Model + * @var \Illuminate\Database\Eloquent\Model */ protected $subscription; /** * Create new Subscription Usage Manager instance. * - * @param \Illuminate\Database\Eloqunet\Model $subscription + * @param \Illuminate\Database\Eloquent\Model $subscription */ public function __construct($subscription) { From 7ffc5c5dfe24ec8f5b0d3c7bb9b8d59df155a246 Mon Sep 17 00:00:00 2001 From: Zac <0zac.bruce@gmail.com> Date: Mon, 31 Jul 2017 17:24:09 +1200 Subject: [PATCH 4/5] Update PlanSubscription.php Add "ended" subscription status to PlanSubscription. --- src/LaraPlans/Models/PlanSubscription.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/LaraPlans/Models/PlanSubscription.php b/src/LaraPlans/Models/PlanSubscription.php index b625078..c8aa01a 100644 --- a/src/LaraPlans/Models/PlanSubscription.php +++ b/src/LaraPlans/Models/PlanSubscription.php @@ -24,8 +24,9 @@ class PlanSubscription extends Model implements PlanSubscriptionInterface /** * Subscription statuses */ - const STATUS_ACTIVE = 'active'; - const STATUS_CANCELED = 'canceled'; + const STATUS_ENDED = 'ended'; + const STATUS_ACTIVE = 'active'; + const STATUS_CANCELED = 'canceled'; /** * The attributes that are mass assignable. @@ -113,6 +114,10 @@ public function getStatusAttribute() if ($this->canceled()) { return self::STATUS_CANCELED; } + + if ($this->ended()) { + return self::STATUS_ENDED; + } } /** From 0d3df94e156de181c13103d5a08f65ac2033c97a Mon Sep 17 00:00:00 2001 From: Zac Bruce Date: Tue, 1 Aug 2017 11:08:18 +1200 Subject: [PATCH 5/5] Add PHPStorm ignore `.idea`. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5298e38..647514c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor /.phpintel -composer.phar \ No newline at end of file +composer.phar +/.idea \ No newline at end of file