From 77e3f025915549b6329f6f0ffbc321a208678fa2 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sun, 18 Feb 2018 05:20:47 +0200 Subject: [PATCH 01/20] Update travis php versions --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f1e0f4b..496c612 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - - 7.0 - 7.1 + - 7.2 env: matrix: From e20334f68f9c62dd521ecf7336300f7dcfe44c50 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Mon, 19 Feb 2018 16:46:49 +0200 Subject: [PATCH 02/20] Rename subscription, plan, and feature "name" to "title" --- README.md | 12 ++++++------ .../2017_05_03_204317_create_plans_table.php | 2 +- .../2017_05_03_204335_create_plan_features_table.php | 2 +- ..._05_03_204353_create_plan_subscriptions_table.php | 2 +- src/Models/Plan.php | 12 ++++++------ src/Models/PlanFeature.php | 12 ++++++------ src/Models/PlanSubscription.php | 12 ++++++------ 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index e01b814..04c0253 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ That's it, we only have to use that trait in our User model! Now your users may ```php $plan = app('rinvex.subscriptions.plan')->create([ - 'name' => 'Pro', + 'title' => 'Pro', 'description' => 'Pro plan', 'price' => 9.99, 'signup_fee' => 1.99, @@ -69,10 +69,10 @@ $plan = app('rinvex.subscriptions.plan')->create([ // Create multiple plan features at once $plan->features()->saveMany([ - new PlanFeature(['name' => 'listings', 'value' => 50, 'sort_order' => 1]), - new PlanFeature(['name' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]), - new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']), - new PlanFeature(['name' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15]) + new PlanFeature(['title' => 'listings', 'value' => 50, 'sort_order' => 1]), + new PlanFeature(['title' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]), + new PlanFeature(['title' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']), + new PlanFeature(['title' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15]) ]); ``` @@ -127,7 +127,7 @@ $plan = app('rinvex.subscriptions.plan')->find(1); $user->newSubscription('main', $plan); ``` -The first argument passed to `newSubscription` method should be the name of the subscription. If your application offer a single subscription, you might call this `main` or `primary`. The second argument is the plan instance your user is subscribing to. +The first argument passed to `newSubscription` method should be the title of the subscription. If your application offer a single subscription, you might call this `main` or `primary`. The second argument is the plan instance your user is subscribing to. ### Change the Plan diff --git a/database/migrations/2017_05_03_204317_create_plans_table.php b/database/migrations/2017_05_03_204317_create_plans_table.php index 5478f74..a35a3fb 100755 --- a/database/migrations/2017_05_03_204317_create_plans_table.php +++ b/database/migrations/2017_05_03_204317_create_plans_table.php @@ -18,7 +18,7 @@ public function up(): void // Columns $table->increments('id'); $table->string('slug'); - $table->{$this->jsonable()}('name'); + $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->boolean('is_active')->default(true); $table->decimal('price')->default('0.00'); diff --git a/database/migrations/2017_05_03_204335_create_plan_features_table.php b/database/migrations/2017_05_03_204335_create_plan_features_table.php index 36c34bb..484159b 100755 --- a/database/migrations/2017_05_03_204335_create_plan_features_table.php +++ b/database/migrations/2017_05_03_204335_create_plan_features_table.php @@ -19,7 +19,7 @@ public function up(): void $table->increments('id'); $table->integer('plan_id')->unsigned(); $table->string('slug'); - $table->{$this->jsonable()}('name'); + $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->string('value'); $table->smallInteger('resettable_period')->unsigned()->default(0); diff --git a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php index 95347a8..f732dfc 100755 --- a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php +++ b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php @@ -19,7 +19,7 @@ public function up(): void $table->morphs('user'); $table->integer('plan_id')->unsigned(); $table->string('slug'); - $table->{$this->jsonable()}('name'); + $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->timestamp('trial_ends_at')->nullable(); $table->timestamp('starts_at')->nullable(); diff --git a/src/Models/Plan.php b/src/Models/Plan.php index 4263ce8..b9284be 100755 --- a/src/Models/Plan.php +++ b/src/Models/Plan.php @@ -19,7 +19,7 @@ * * @property int $id * @property string $slug - * @property array $name + * @property array $title * @property array $description * @property bool $is_active * @property float $price @@ -54,7 +54,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereInvoiceInterval($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereInvoicePeriod($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereIsActive($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereTitle($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan wherePrice($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProrateDay($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProrateExtendDue($value) @@ -80,7 +80,7 @@ class Plan extends Model implements Sortable */ protected $fillable = [ 'slug', - 'name', + 'title', 'description', 'is_active', 'price', @@ -136,7 +136,7 @@ class Plan extends Model implements Sortable * @var array */ public $translatable = [ - 'name', + 'title', 'description', ]; @@ -176,7 +176,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plans')); $this->setRules([ 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plans').',slug', - 'name' => 'required|string|max:150', + 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'is_active' => 'sometimes|boolean', 'price' => 'required|numeric', @@ -205,7 +205,7 @@ public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('name') + ->generateSlugsFrom('title') ->saveSlugsTo('slug'); } diff --git a/src/Models/PlanFeature.php b/src/Models/PlanFeature.php index 8ceb31a..bd93a6c 100755 --- a/src/Models/PlanFeature.php +++ b/src/Models/PlanFeature.php @@ -23,7 +23,7 @@ * @property int $id * @property int $plan_id * @property string $slug - * @property array $name + * @property array $title * @property array $description * @property string $value * @property int $resettable_period @@ -41,7 +41,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereDescription($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereTitle($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature wherePlanId($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereResettableInterval($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereResettablePeriod($value) @@ -66,7 +66,7 @@ class PlanFeature extends Model implements Sortable protected $fillable = [ 'plan_id', 'slug', - 'name', + 'title', 'description', 'value', 'resettable_period', @@ -101,7 +101,7 @@ class PlanFeature extends Model implements Sortable * @var array */ public $translatable = [ - 'name', + 'title', 'description', ]; @@ -142,7 +142,7 @@ public function __construct(array $attributes = []) $this->setRules([ 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_features').',slug', - 'name' => 'required|string|max:150', + 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'value' => 'required|string', 'resettable_period' => 'sometimes|integer', @@ -160,7 +160,7 @@ public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('name') + ->generateSlugsFrom('title') ->saveSlugsTo('slug'); } diff --git a/src/Models/PlanSubscription.php b/src/Models/PlanSubscription.php index a06063c..1c2567e 100755 --- a/src/Models/PlanSubscription.php +++ b/src/Models/PlanSubscription.php @@ -26,7 +26,7 @@ * @property string $user_type * @property int $plan_id * @property string $slug - * @property array $name + * @property array $title * @property array $description * @property \Carbon\Carbon $trial_ends_at * @property \Carbon\Carbon $starts_at @@ -53,7 +53,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereDescription($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereEndsAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereTitle($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription wherePlanId($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereSlug($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereStartsAt($value) @@ -79,7 +79,7 @@ class PlanSubscription extends Model 'user_type', 'plan_id', 'slug', - 'name', + 'title', 'description', 'trial_ends_at', 'starts_at', @@ -118,7 +118,7 @@ class PlanSubscription extends Model * @var array */ public $translatable = [ - 'name', + 'title', 'description', ]; @@ -148,7 +148,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plan_subscriptions')); $this->setRules([ - 'name' => 'required|string|max:150', + 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_subscriptions').',slug', 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', @@ -185,7 +185,7 @@ public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('name') + ->generateSlugsFrom('title') ->saveSlugsTo('slug'); } From e8a3f77ea2eccaed3347b94c277860eebde4581a Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Mon, 19 Feb 2018 18:56:51 +0200 Subject: [PATCH 03/20] Rename subscription, plan, and feature "slug" to "name" --- README.md | 10 ++-- .../2017_05_03_204317_create_plans_table.php | 4 +- ...5_03_204335_create_plan_features_table.php | 4 +- ...204353_create_plan_subscriptions_table.php | 4 +- src/Models/Plan.php | 20 +++---- src/Models/PlanFeature.php | 14 ++--- src/Models/PlanSubscription.php | 52 +++++++++---------- src/Models/PlanSubscriptionUsage.php | 10 ++-- 8 files changed, 59 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 04c0253..3e3ad65 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ $plan->hasTrial(); $plan->hasGrace(); ``` -Both `$plan->features` and `$plan->subscriptions` are collections, driven from relationships, and thus you can query these relations as any normal Eloquent relationship. E.g. `$plan->features()->where('slug', 'listing_title_bold')->first()`. +Both `$plan->features` and `$plan->subscriptions` are collections, driven from relationships, and thus you can query these relations as any normal Eloquent relationship. E.g. `$plan->features()->where('name', 'listing_title_bold')->first()`. ### Get Feature Value @@ -107,10 +107,10 @@ Say you want to show the value of the feature _pictures_per_listing_ from above. ```php // Use the plan instance to get feature's value -$amountOfPictures = $plan->getFeatureBySlug('pictures_per_listing')->value; +$amountOfPictures = $plan->getFeatureByName('pictures_per_listing')->value; // Query the feature itself directly -$amountOfPictures = app('rinvex.subscriptions.plan_feature')->where('slug', 'pictures_per_listing')->first()->value; +$amountOfPictures = app('rinvex.subscriptions.plan_feature')->where('name', 'pictures_per_listing')->first()->value; // Get feature value through the subscription instance $amountOfPictures = app('rinvex.subscriptions.plan_subscription')->find(1)->getFeatureValue('pictures_per_listing'); @@ -149,7 +149,7 @@ Plan features are great for fine tuning subscriptions, you can topup certain fea ```php // Find plan feature -$feature = app('rinvex.subscriptions.plan_feature')->where('slug', 'listing_duration_days')->first(); +$feature = app('rinvex.subscriptions.plan_feature')->where('name', 'listing_duration_days')->first(); // Get feature reset date $feature->getResetDate(new \Carbon\Carbon()); @@ -185,7 +185,7 @@ In order to effectively use the ability methods you will need to keep track of e $user->subscription('main')->recordFeatureUsage('listings'); ``` -The `recordFeatureUsage` method accept 3 parameters: the first one is the feature's slug, the second one is the quantity of uses to add (default is `1`), and the third one indicates if the addition should be incremental (default behavior), when disabled the usage will be override by the quantity provided. E.g.: +The `recordFeatureUsage` method accept 3 parameters: the first one is the feature's name, the second one is the quantity of uses to add (default is `1`), and the third one indicates if the addition should be incremental (default behavior), when disabled the usage will be override by the quantity provided. E.g.: ```php // Increment by 2 diff --git a/database/migrations/2017_05_03_204317_create_plans_table.php b/database/migrations/2017_05_03_204317_create_plans_table.php index a35a3fb..53b414d 100755 --- a/database/migrations/2017_05_03_204317_create_plans_table.php +++ b/database/migrations/2017_05_03_204317_create_plans_table.php @@ -17,7 +17,7 @@ public function up(): void Schema::create(config('rinvex.subscriptions.tables.plans'), function (Blueprint $table) { // Columns $table->increments('id'); - $table->string('slug'); + $table->string('name'); $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->boolean('is_active')->default(true); @@ -39,7 +39,7 @@ public function up(): void $table->softDeletes(); // Indexes - $table->unique('slug'); + $table->unique('name'); }); } diff --git a/database/migrations/2017_05_03_204335_create_plan_features_table.php b/database/migrations/2017_05_03_204335_create_plan_features_table.php index 484159b..e4d0407 100755 --- a/database/migrations/2017_05_03_204335_create_plan_features_table.php +++ b/database/migrations/2017_05_03_204335_create_plan_features_table.php @@ -18,7 +18,7 @@ public function up(): void // Columns $table->increments('id'); $table->integer('plan_id')->unsigned(); - $table->string('slug'); + $table->string('name'); $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->string('value'); @@ -29,7 +29,7 @@ public function up(): void $table->softDeletes(); // Indexes - $table->unique(['plan_id', 'slug']); + $table->unique(['plan_id', 'name']); $table->foreign('plan_id')->references('id')->on(config('rinvex.subscriptions.tables.plans')) ->onDelete('cascade')->onUpdate('cascade'); }); diff --git a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php index f732dfc..b15c3dd 100755 --- a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php +++ b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php @@ -18,7 +18,7 @@ public function up(): void $table->increments('id'); $table->morphs('user'); $table->integer('plan_id')->unsigned(); - $table->string('slug'); + $table->string('name'); $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->timestamp('trial_ends_at')->nullable(); @@ -30,7 +30,7 @@ public function up(): void $table->softDeletes(); // Indexes - $table->unique('slug'); + $table->unique('name'); $table->foreign('plan_id')->references('id')->on(config('rinvex.subscriptions.tables.plans')) ->onDelete('cascade')->onUpdate('cascade'); }); diff --git a/src/Models/Plan.php b/src/Models/Plan.php index b9284be..cf34d2f 100755 --- a/src/Models/Plan.php +++ b/src/Models/Plan.php @@ -18,7 +18,7 @@ * Rinvex\Subscriptions\Models\Plan. * * @property int $id - * @property string $slug + * @property string $name * @property array $title * @property array $description * @property bool $is_active @@ -60,7 +60,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProrateExtendDue($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProratePeriod($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSignupFee($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSlug($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSortOrder($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereTrialInterval($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereTrialPeriod($value) @@ -79,7 +79,7 @@ class Plan extends Model implements Sortable * {@inheritdoc} */ protected $fillable = [ - 'slug', + 'name', 'title', 'description', 'is_active', @@ -103,7 +103,7 @@ class Plan extends Model implements Sortable * {@inheritdoc} */ protected $casts = [ - 'slug' => 'string', + 'name' => 'string', 'is_active' => 'boolean', 'price' => 'float', 'signup_fee' => 'float', @@ -175,7 +175,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plans')); $this->setRules([ - 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plans').',slug', + 'name' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plans').',name', 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'is_active' => 'sometimes|boolean', @@ -206,7 +206,7 @@ public function getSlugOptions(): SlugOptions return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() ->generateSlugsFrom('title') - ->saveSlugsTo('slug'); + ->saveSlugsTo('name'); } /** @@ -260,15 +260,15 @@ public function hasGrace(): bool } /** - * Get plan feature by the given slug. + * Get plan feature by the given name. * - * @param string $featureSlug + * @param string $featureName * * @return \Rinvex\Subscriptions\Models\PlanFeature|null */ - public function getFeatureBySlug(string $featureSlug): ?PlanFeature + public function getFeatureByName(string $featureName): ?PlanFeature { - return $this->features()->where('slug', $featureSlug)->first(); + return $this->features()->where('name', $featureName)->first(); } /** diff --git a/src/Models/PlanFeature.php b/src/Models/PlanFeature.php index bd93a6c..e342f42 100755 --- a/src/Models/PlanFeature.php +++ b/src/Models/PlanFeature.php @@ -22,7 +22,7 @@ * * @property int $id * @property int $plan_id - * @property string $slug + * @property string $name * @property array $title * @property array $description * @property string $value @@ -45,7 +45,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature wherePlanId($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereResettableInterval($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereResettablePeriod($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereSlug($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereSortOrder($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereValue($value) @@ -65,7 +65,7 @@ class PlanFeature extends Model implements Sortable */ protected $fillable = [ 'plan_id', - 'slug', + 'name', 'title', 'description', 'value', @@ -79,7 +79,7 @@ class PlanFeature extends Model implements Sortable */ protected $casts = [ 'plan_id' => 'integer', - 'slug' => 'string', + 'name' => 'string', 'value' => 'string', 'resettable_period' => 'integer', 'resettable_interval' => 'string', @@ -141,7 +141,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plan_features')); $this->setRules([ 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', - 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_features').',slug', + 'name' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_features').',name', 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'value' => 'required|string', @@ -152,7 +152,7 @@ public function __construct(array $attributes = []) } /** - * Get the options for generating the slug. + * Get the options for generating the name. * * @return \Spatie\Sluggable\SlugOptions */ @@ -161,7 +161,7 @@ public function getSlugOptions(): SlugOptions return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() ->generateSlugsFrom('title') - ->saveSlugsTo('slug'); + ->saveSlugsTo('name'); } /** diff --git a/src/Models/PlanSubscription.php b/src/Models/PlanSubscription.php index 1c2567e..8438708 100755 --- a/src/Models/PlanSubscription.php +++ b/src/Models/PlanSubscription.php @@ -25,7 +25,7 @@ * @property int $user_id * @property string $user_type * @property int $plan_id - * @property string $slug + * @property string $name * @property array $title * @property array $description * @property \Carbon\Carbon $trial_ends_at @@ -55,7 +55,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereTitle($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription wherePlanId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereSlug($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereStartsAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereTrialEndsAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereUpdatedAt($value) @@ -78,7 +78,7 @@ class PlanSubscription extends Model 'user_id', 'user_type', 'plan_id', - 'slug', + 'name', 'title', 'description', 'trial_ends_at', @@ -95,7 +95,7 @@ class PlanSubscription extends Model 'user_id' => 'integer', 'user_type' => 'string', 'plan_id' => 'integer', - 'slug' => 'string', + 'name' => 'string', 'trial_ends_at' => 'datetime', 'starts_at' => 'datetime', 'ends_at' => 'datetime', @@ -150,7 +150,7 @@ public function __construct(array $attributes = []) $this->setRules([ 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', - 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_subscriptions').',slug', + 'name' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_subscriptions').',name', 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', 'user_id' => 'required|integer', 'user_type' => 'required|string', @@ -186,7 +186,7 @@ public function getSlugOptions(): SlugOptions return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() ->generateSlugsFrom('title') - ->saveSlugsTo('slug'); + ->saveSlugsTo('name'); } /** @@ -431,14 +431,14 @@ protected function setNewPeriod($invoice_interval = '', $invoice_period = '', $s /** * Record feature usage. * - * @param string $featureSlug + * @param string $featureName * @param int $uses * * @return \Rinvex\Subscriptions\Models\PlanSubscriptionUsage */ - public function recordFeatureUsage(string $featureSlug, int $uses = 1, bool $incremental = true): PlanSubscriptionUsage + public function recordFeatureUsage(string $featureName, int $uses = 1, bool $incremental = true): PlanSubscriptionUsage { - $feature = $this->plan->features()->where('slug', $featureSlug)->first(); + $feature = $this->plan->features()->where('name', $featureName)->first(); $usage = $this->usage()->firstOrNew([ 'subscription_id' => $this->getKey(), @@ -469,14 +469,14 @@ public function recordFeatureUsage(string $featureSlug, int $uses = 1, bool $inc /** * Reduce usage. * - * @param string $featureSlug + * @param string $featureName * @param int $uses * * @return \Rinvex\Subscriptions\Models\PlanSubscriptionUsage|null */ - public function reduceFeatureUsage(string $featureSlug, int $uses = 1): ?PlanSubscriptionUsage + public function reduceFeatureUsage(string $featureName, int $uses = 1): ?PlanSubscriptionUsage { - $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); + $usage = $this->usage()->byFeatureName($featureName)->first(); if (is_null($usage)) { return null; @@ -492,14 +492,14 @@ public function reduceFeatureUsage(string $featureSlug, int $uses = 1): ?PlanSub /** * Determine if the feature can be used. * - * @param string $featureSlug + * @param string $featureName * * @return bool */ - public function canUseFeature(string $featureSlug): bool + public function canUseFeature(string $featureName): bool { - $featureValue = $this->getFeatureValue($featureSlug); - $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); + $featureValue = $this->getFeatureValue($featureName); + $usage = $this->usage()->byFeatureName($featureName)->first(); if ($featureValue === 'true') { return true; @@ -512,19 +512,19 @@ public function canUseFeature(string $featureSlug): bool } // Check for available uses - return $this->getFeatureRemainings($featureSlug) > 0; + return $this->getFeatureRemainings($featureName) > 0; } /** * Get how many times the feature has been used. * - * @param string $featureSlug + * @param string $featureName * * @return int */ - public function getFeatureUsage(string $featureSlug): int + public function getFeatureUsage(string $featureName): int { - $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); + $usage = $this->usage()->byFeatureName($featureName)->first(); return ! $usage->expired() ? $usage->used : 0; } @@ -532,25 +532,25 @@ public function getFeatureUsage(string $featureSlug): int /** * Get the available uses. * - * @param string $featureSlug + * @param string $featureName * * @return int */ - public function getFeatureRemainings(string $featureSlug): int + public function getFeatureRemainings(string $featureName): int { - return $this->getFeatureValue($featureSlug) - $this->getFeatureUsage($featureSlug); + return $this->getFeatureValue($featureName) - $this->getFeatureUsage($featureName); } /** * Get feature value. * - * @param string $featureSlug + * @param string $featureName * * @return mixed */ - public function getFeatureValue(string $featureSlug) + public function getFeatureValue(string $featureName) { - $feature = $this->plan->features()->where('slug', $featureSlug)->first(); + $feature = $this->plan->features()->where('name', $featureName)->first(); return $feature->value ?? null; } diff --git a/src/Models/PlanSubscriptionUsage.php b/src/Models/PlanSubscriptionUsage.php index f917a24..b939bea 100755 --- a/src/Models/PlanSubscriptionUsage.php +++ b/src/Models/PlanSubscriptionUsage.php @@ -24,7 +24,7 @@ * @property-read \Rinvex\Subscriptions\Models\PlanFeature $feature * @property-read \Rinvex\Subscriptions\Models\PlanSubscription $subscription * - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage byFeatureSlug($featureSlug) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage byFeatureName($featureName) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereFeatureId($value) @@ -123,16 +123,16 @@ public function subscription(): BelongsTo } /** - * Scope subscription usage by feature slug. + * Scope subscription usage by feature name. * * @param \Illuminate\Database\Eloquent\Builder $builder - * @param string $featureSlug + * @param string $featureName * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeByFeatureSlug(Builder $builder, string $featureSlug): Builder + public function scopeByFeatureName(Builder $builder, string $featureName): Builder { - $feature = PlanFeature::where('slug', $featureSlug)->first(); + $feature = PlanFeature::where('name', $featureName)->first(); return $builder->where('feature_id', $feature->getKey() ?? null); } From f3d51ff17639c45ee0864ea1158111335bc35d87 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 20 Feb 2018 12:24:18 +0200 Subject: [PATCH 04/20] Define polymorphic relationship parameters explicitly --- src/Models/PlanSubscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/PlanSubscription.php b/src/Models/PlanSubscription.php index 8438708..b0c7620 100755 --- a/src/Models/PlanSubscription.php +++ b/src/Models/PlanSubscription.php @@ -196,7 +196,7 @@ public function getSlugOptions(): SlugOptions */ public function user(): MorphTo { - return $this->morphTo(); + return $this->morphTo('user', 'user_type', 'user_id'); } /** From 285f08eaec97048b4fec58da51ef8c083fdf5847 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Mon, 26 Feb 2018 22:30:53 +0200 Subject: [PATCH 05/20] Fix fully qualified booking unit methods (fix #20) --- src/Services/Period.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Services/Period.php b/src/Services/Period.php index 8664fae..3907249 100755 --- a/src/Services/Period.php +++ b/src/Services/Period.php @@ -45,7 +45,7 @@ class Period * * @return void */ - public function __construct($interval = 'm', $count = 1, $start = '') + public function __construct($interval = 'month', $count = 1, $start = '') { if (empty($start)) { $this->start = now(); @@ -55,14 +55,12 @@ public function __construct($interval = 'm', $count = 1, $start = '') $this->start = $start; } - $this->interval = in_array($interval, ['d', 'w', 'm', 'y']) ? $interval : 'm'; - if ($count > 0) { $this->period = $count; } - $method = 'add'.ucfirst($this->interval).'s'; $start = clone $this->start; + $method = 'add'.ucfirst($this->interval).'s'; $this->end = $start->$method($this->period); } From 96dad848fbc3d1aeb1a367231dc651b16749bf12 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 27 Feb 2018 16:24:07 +0200 Subject: [PATCH 06/20] Rename slug field into name --- src/Traits/HasSubscriptions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Traits/HasSubscriptions.php b/src/Traits/HasSubscriptions.php index 63c5a21..1b69cd8 100755 --- a/src/Traits/HasSubscriptions.php +++ b/src/Traits/HasSubscriptions.php @@ -46,15 +46,15 @@ public function activeSubscriptions(): Collection } /** - * Get a subscription by slug. + * Get a subscription by name. * - * @param string $subscriptionSlug + * @param string $subscriptionName * * @return \Rinvex\Subscriptions\Models\PlanSubscription|null */ - public function subscription(string $subscriptionSlug): ?PlanSubscription + public function subscription(string $subscriptionName): ?PlanSubscription { - return $this->subscriptions()->where('slug', $subscriptionSlug)->first(); + return $this->subscriptions()->where('name', $subscriptionName)->first(); } /** From 063d8b2b4cd6429cd68f78f99ca2bce96dfcaa15 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 27 Feb 2018 16:27:20 +0200 Subject: [PATCH 07/20] Fix subscription title field naming --- src/Traits/HasSubscriptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/HasSubscriptions.php b/src/Traits/HasSubscriptions.php index 1b69cd8..50edefe 100755 --- a/src/Traits/HasSubscriptions.php +++ b/src/Traits/HasSubscriptions.php @@ -97,7 +97,7 @@ public function newSubscription($subscription, Plan $plan): PlanSubscription $period = new Period($plan->invoice_interval, $plan->invoice_period, $trial->getEndDate()); return $this->subscriptions()->create([ - 'name' => $subscription, + 'title' => $subscription, 'plan_id' => $plan->getKey(), 'trial_ends_at' => $trial->getEndDate(), 'starts_at' => $period->getStartDate(), From 047217ffba34c04699418711f33d795aef3e94bb Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 29 Mar 2018 18:27:37 +0200 Subject: [PATCH 08/20] Revert names to slugs again! SORRY!! --- .../2017_05_03_204317_create_plans_table.php | 4 +- ...5_03_204335_create_plan_features_table.php | 4 +- ...204353_create_plan_subscriptions_table.php | 4 +- src/Models/Plan.php | 20 +++---- src/Models/PlanFeature.php | 14 ++--- src/Models/PlanSubscription.php | 52 +++++++++---------- src/Traits/HasSubscriptions.php | 8 +-- 7 files changed, 53 insertions(+), 53 deletions(-) diff --git a/database/migrations/2017_05_03_204317_create_plans_table.php b/database/migrations/2017_05_03_204317_create_plans_table.php index 53b414d..a35a3fb 100755 --- a/database/migrations/2017_05_03_204317_create_plans_table.php +++ b/database/migrations/2017_05_03_204317_create_plans_table.php @@ -17,7 +17,7 @@ public function up(): void Schema::create(config('rinvex.subscriptions.tables.plans'), function (Blueprint $table) { // Columns $table->increments('id'); - $table->string('name'); + $table->string('slug'); $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->boolean('is_active')->default(true); @@ -39,7 +39,7 @@ public function up(): void $table->softDeletes(); // Indexes - $table->unique('name'); + $table->unique('slug'); }); } diff --git a/database/migrations/2017_05_03_204335_create_plan_features_table.php b/database/migrations/2017_05_03_204335_create_plan_features_table.php index e4d0407..484159b 100755 --- a/database/migrations/2017_05_03_204335_create_plan_features_table.php +++ b/database/migrations/2017_05_03_204335_create_plan_features_table.php @@ -18,7 +18,7 @@ public function up(): void // Columns $table->increments('id'); $table->integer('plan_id')->unsigned(); - $table->string('name'); + $table->string('slug'); $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->string('value'); @@ -29,7 +29,7 @@ public function up(): void $table->softDeletes(); // Indexes - $table->unique(['plan_id', 'name']); + $table->unique(['plan_id', 'slug']); $table->foreign('plan_id')->references('id')->on(config('rinvex.subscriptions.tables.plans')) ->onDelete('cascade')->onUpdate('cascade'); }); diff --git a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php index b15c3dd..f732dfc 100755 --- a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php +++ b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php @@ -18,7 +18,7 @@ public function up(): void $table->increments('id'); $table->morphs('user'); $table->integer('plan_id')->unsigned(); - $table->string('name'); + $table->string('slug'); $table->{$this->jsonable()}('title'); $table->{$this->jsonable()}('description')->nullable(); $table->timestamp('trial_ends_at')->nullable(); @@ -30,7 +30,7 @@ public function up(): void $table->softDeletes(); // Indexes - $table->unique('name'); + $table->unique('slug'); $table->foreign('plan_id')->references('id')->on(config('rinvex.subscriptions.tables.plans')) ->onDelete('cascade')->onUpdate('cascade'); }); diff --git a/src/Models/Plan.php b/src/Models/Plan.php index cf34d2f..b9284be 100755 --- a/src/Models/Plan.php +++ b/src/Models/Plan.php @@ -18,7 +18,7 @@ * Rinvex\Subscriptions\Models\Plan. * * @property int $id - * @property string $name + * @property string $slug * @property array $title * @property array $description * @property bool $is_active @@ -60,7 +60,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProrateExtendDue($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProratePeriod($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSignupFee($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSlug($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSortOrder($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereTrialInterval($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereTrialPeriod($value) @@ -79,7 +79,7 @@ class Plan extends Model implements Sortable * {@inheritdoc} */ protected $fillable = [ - 'name', + 'slug', 'title', 'description', 'is_active', @@ -103,7 +103,7 @@ class Plan extends Model implements Sortable * {@inheritdoc} */ protected $casts = [ - 'name' => 'string', + 'slug' => 'string', 'is_active' => 'boolean', 'price' => 'float', 'signup_fee' => 'float', @@ -175,7 +175,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plans')); $this->setRules([ - 'name' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plans').',name', + 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plans').',slug', 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'is_active' => 'sometimes|boolean', @@ -206,7 +206,7 @@ public function getSlugOptions(): SlugOptions return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() ->generateSlugsFrom('title') - ->saveSlugsTo('name'); + ->saveSlugsTo('slug'); } /** @@ -260,15 +260,15 @@ public function hasGrace(): bool } /** - * Get plan feature by the given name. + * Get plan feature by the given slug. * - * @param string $featureName + * @param string $featureSlug * * @return \Rinvex\Subscriptions\Models\PlanFeature|null */ - public function getFeatureByName(string $featureName): ?PlanFeature + public function getFeatureBySlug(string $featureSlug): ?PlanFeature { - return $this->features()->where('name', $featureName)->first(); + return $this->features()->where('slug', $featureSlug)->first(); } /** diff --git a/src/Models/PlanFeature.php b/src/Models/PlanFeature.php index e342f42..bd93a6c 100755 --- a/src/Models/PlanFeature.php +++ b/src/Models/PlanFeature.php @@ -22,7 +22,7 @@ * * @property int $id * @property int $plan_id - * @property string $name + * @property string $slug * @property array $title * @property array $description * @property string $value @@ -45,7 +45,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature wherePlanId($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereResettableInterval($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereResettablePeriod($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereSlug($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereSortOrder($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereValue($value) @@ -65,7 +65,7 @@ class PlanFeature extends Model implements Sortable */ protected $fillable = [ 'plan_id', - 'name', + 'slug', 'title', 'description', 'value', @@ -79,7 +79,7 @@ class PlanFeature extends Model implements Sortable */ protected $casts = [ 'plan_id' => 'integer', - 'name' => 'string', + 'slug' => 'string', 'value' => 'string', 'resettable_period' => 'integer', 'resettable_interval' => 'string', @@ -141,7 +141,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plan_features')); $this->setRules([ 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', - 'name' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_features').',name', + 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_features').',slug', 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'value' => 'required|string', @@ -152,7 +152,7 @@ public function __construct(array $attributes = []) } /** - * Get the options for generating the name. + * Get the options for generating the slug. * * @return \Spatie\Sluggable\SlugOptions */ @@ -161,7 +161,7 @@ public function getSlugOptions(): SlugOptions return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() ->generateSlugsFrom('title') - ->saveSlugsTo('name'); + ->saveSlugsTo('slug'); } /** diff --git a/src/Models/PlanSubscription.php b/src/Models/PlanSubscription.php index b0c7620..df195f1 100755 --- a/src/Models/PlanSubscription.php +++ b/src/Models/PlanSubscription.php @@ -25,7 +25,7 @@ * @property int $user_id * @property string $user_type * @property int $plan_id - * @property string $name + * @property string $slug * @property array $title * @property array $description * @property \Carbon\Carbon $trial_ends_at @@ -55,7 +55,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereTitle($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription wherePlanId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereSlug($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereStartsAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereTrialEndsAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereUpdatedAt($value) @@ -78,7 +78,7 @@ class PlanSubscription extends Model 'user_id', 'user_type', 'plan_id', - 'name', + 'slug', 'title', 'description', 'trial_ends_at', @@ -95,7 +95,7 @@ class PlanSubscription extends Model 'user_id' => 'integer', 'user_type' => 'string', 'plan_id' => 'integer', - 'name' => 'string', + 'slug' => 'string', 'trial_ends_at' => 'datetime', 'starts_at' => 'datetime', 'ends_at' => 'datetime', @@ -150,7 +150,7 @@ public function __construct(array $attributes = []) $this->setRules([ 'title' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', - 'name' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_subscriptions').',name', + 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_subscriptions').',slug', 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', 'user_id' => 'required|integer', 'user_type' => 'required|string', @@ -186,7 +186,7 @@ public function getSlugOptions(): SlugOptions return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() ->generateSlugsFrom('title') - ->saveSlugsTo('name'); + ->saveSlugsTo('slug'); } /** @@ -431,14 +431,14 @@ protected function setNewPeriod($invoice_interval = '', $invoice_period = '', $s /** * Record feature usage. * - * @param string $featureName + * @param string $featureSlug * @param int $uses * * @return \Rinvex\Subscriptions\Models\PlanSubscriptionUsage */ - public function recordFeatureUsage(string $featureName, int $uses = 1, bool $incremental = true): PlanSubscriptionUsage + public function recordFeatureUsage(string $featureSlug, int $uses = 1, bool $incremental = true): PlanSubscriptionUsage { - $feature = $this->plan->features()->where('name', $featureName)->first(); + $feature = $this->plan->features()->where('slug', $featureSlug)->first(); $usage = $this->usage()->firstOrNew([ 'subscription_id' => $this->getKey(), @@ -469,14 +469,14 @@ public function recordFeatureUsage(string $featureName, int $uses = 1, bool $inc /** * Reduce usage. * - * @param string $featureName + * @param string $featureSlug * @param int $uses * * @return \Rinvex\Subscriptions\Models\PlanSubscriptionUsage|null */ - public function reduceFeatureUsage(string $featureName, int $uses = 1): ?PlanSubscriptionUsage + public function reduceFeatureUsage(string $featureSlug, int $uses = 1): ?PlanSubscriptionUsage { - $usage = $this->usage()->byFeatureName($featureName)->first(); + $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); if (is_null($usage)) { return null; @@ -492,14 +492,14 @@ public function reduceFeatureUsage(string $featureName, int $uses = 1): ?PlanSub /** * Determine if the feature can be used. * - * @param string $featureName + * @param string $featureSlug * * @return bool */ - public function canUseFeature(string $featureName): bool + public function canUseFeature(string $featureSlug): bool { - $featureValue = $this->getFeatureValue($featureName); - $usage = $this->usage()->byFeatureName($featureName)->first(); + $featureValue = $this->getFeatureValue($featureSlug); + $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); if ($featureValue === 'true') { return true; @@ -512,19 +512,19 @@ public function canUseFeature(string $featureName): bool } // Check for available uses - return $this->getFeatureRemainings($featureName) > 0; + return $this->getFeatureRemainings($featureSlug) > 0; } /** * Get how many times the feature has been used. * - * @param string $featureName + * @param string $featureSlug * * @return int */ - public function getFeatureUsage(string $featureName): int + public function getFeatureUsage(string $featureSlug): int { - $usage = $this->usage()->byFeatureName($featureName)->first(); + $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); return ! $usage->expired() ? $usage->used : 0; } @@ -532,25 +532,25 @@ public function getFeatureUsage(string $featureName): int /** * Get the available uses. * - * @param string $featureName + * @param string $featureSlug * * @return int */ - public function getFeatureRemainings(string $featureName): int + public function getFeatureRemainings(string $featureSlug): int { - return $this->getFeatureValue($featureName) - $this->getFeatureUsage($featureName); + return $this->getFeatureValue($featureSlug) - $this->getFeatureUsage($featureSlug); } /** * Get feature value. * - * @param string $featureName + * @param string $featureSlug * * @return mixed */ - public function getFeatureValue(string $featureName) + public function getFeatureValue(string $featureSlug) { - $feature = $this->plan->features()->where('name', $featureName)->first(); + $feature = $this->plan->features()->where('slug', $featureSlug)->first(); return $feature->value ?? null; } diff --git a/src/Traits/HasSubscriptions.php b/src/Traits/HasSubscriptions.php index 50edefe..dc0aee2 100755 --- a/src/Traits/HasSubscriptions.php +++ b/src/Traits/HasSubscriptions.php @@ -46,15 +46,15 @@ public function activeSubscriptions(): Collection } /** - * Get a subscription by name. + * Get a subscription by slug. * - * @param string $subscriptionName + * @param string $subscriptionSlug * * @return \Rinvex\Subscriptions\Models\PlanSubscription|null */ - public function subscription(string $subscriptionName): ?PlanSubscription + public function subscription(string $subscriptionSlug): ?PlanSubscription { - return $this->subscriptions()->where('name', $subscriptionName)->first(); + return $this->subscriptions()->where('slug', $subscriptionSlug)->first(); } /** From e3cb7aab0620bda50d086f887df191db1369b4b5 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 29 Mar 2018 19:52:43 +0200 Subject: [PATCH 09/20] Revert titles to names again! SORRY!! --- README.md | 10 +++++----- .../2017_05_03_204317_create_plans_table.php | 2 +- .../2017_05_03_204335_create_plan_features_table.php | 2 +- ..._05_03_204353_create_plan_subscriptions_table.php | 2 +- src/Models/Plan.php | 12 ++++++------ src/Models/PlanFeature.php | 8 ++++---- src/Models/PlanSubscription.php | 8 ++++---- src/Traits/HasSubscriptions.php | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3e3ad65..33e6000 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ That's it, we only have to use that trait in our User model! Now your users may ```php $plan = app('rinvex.subscriptions.plan')->create([ - 'title' => 'Pro', + 'name' => 'Pro', 'description' => 'Pro plan', 'price' => 9.99, 'signup_fee' => 1.99, @@ -69,10 +69,10 @@ $plan = app('rinvex.subscriptions.plan')->create([ // Create multiple plan features at once $plan->features()->saveMany([ - new PlanFeature(['title' => 'listings', 'value' => 50, 'sort_order' => 1]), - new PlanFeature(['title' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]), - new PlanFeature(['title' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']), - new PlanFeature(['title' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15]) + new PlanFeature(['name' => 'listings', 'value' => 50, 'sort_order' => 1]), + new PlanFeature(['name' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]), + new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']), + new PlanFeature(['name' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15]) ]); ``` diff --git a/database/migrations/2017_05_03_204317_create_plans_table.php b/database/migrations/2017_05_03_204317_create_plans_table.php index a35a3fb..5478f74 100755 --- a/database/migrations/2017_05_03_204317_create_plans_table.php +++ b/database/migrations/2017_05_03_204317_create_plans_table.php @@ -18,7 +18,7 @@ public function up(): void // Columns $table->increments('id'); $table->string('slug'); - $table->{$this->jsonable()}('title'); + $table->{$this->jsonable()}('name'); $table->{$this->jsonable()}('description')->nullable(); $table->boolean('is_active')->default(true); $table->decimal('price')->default('0.00'); diff --git a/database/migrations/2017_05_03_204335_create_plan_features_table.php b/database/migrations/2017_05_03_204335_create_plan_features_table.php index 484159b..36c34bb 100755 --- a/database/migrations/2017_05_03_204335_create_plan_features_table.php +++ b/database/migrations/2017_05_03_204335_create_plan_features_table.php @@ -19,7 +19,7 @@ public function up(): void $table->increments('id'); $table->integer('plan_id')->unsigned(); $table->string('slug'); - $table->{$this->jsonable()}('title'); + $table->{$this->jsonable()}('name'); $table->{$this->jsonable()}('description')->nullable(); $table->string('value'); $table->smallInteger('resettable_period')->unsigned()->default(0); diff --git a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php index f732dfc..95347a8 100755 --- a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php +++ b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php @@ -19,7 +19,7 @@ public function up(): void $table->morphs('user'); $table->integer('plan_id')->unsigned(); $table->string('slug'); - $table->{$this->jsonable()}('title'); + $table->{$this->jsonable()}('name'); $table->{$this->jsonable()}('description')->nullable(); $table->timestamp('trial_ends_at')->nullable(); $table->timestamp('starts_at')->nullable(); diff --git a/src/Models/Plan.php b/src/Models/Plan.php index b9284be..4263ce8 100755 --- a/src/Models/Plan.php +++ b/src/Models/Plan.php @@ -19,7 +19,7 @@ * * @property int $id * @property string $slug - * @property array $title + * @property array $name * @property array $description * @property bool $is_active * @property float $price @@ -54,7 +54,7 @@ * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereInvoiceInterval($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereInvoicePeriod($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereIsActive($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereTitle($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan wherePrice($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProrateDay($value) * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProrateExtendDue($value) @@ -80,7 +80,7 @@ class Plan extends Model implements Sortable */ protected $fillable = [ 'slug', - 'title', + 'name', 'description', 'is_active', 'price', @@ -136,7 +136,7 @@ class Plan extends Model implements Sortable * @var array */ public $translatable = [ - 'title', + 'name', 'description', ]; @@ -176,7 +176,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plans')); $this->setRules([ 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plans').',slug', - 'title' => 'required|string|max:150', + 'name' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'is_active' => 'sometimes|boolean', 'price' => 'required|numeric', @@ -205,7 +205,7 @@ public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('title') + ->generateSlugsFrom('name') ->saveSlugsTo('slug'); } diff --git a/src/Models/PlanFeature.php b/src/Models/PlanFeature.php index bd93a6c..58f2a60 100755 --- a/src/Models/PlanFeature.php +++ b/src/Models/PlanFeature.php @@ -66,7 +66,7 @@ class PlanFeature extends Model implements Sortable protected $fillable = [ 'plan_id', 'slug', - 'title', + 'name', 'description', 'value', 'resettable_period', @@ -101,7 +101,7 @@ class PlanFeature extends Model implements Sortable * @var array */ public $translatable = [ - 'title', + 'name', 'description', ]; @@ -142,7 +142,7 @@ public function __construct(array $attributes = []) $this->setRules([ 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_features').',slug', - 'title' => 'required|string|max:150', + 'name' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'value' => 'required|string', 'resettable_period' => 'sometimes|integer', @@ -160,7 +160,7 @@ public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('title') + ->generateSlugsFrom('name') ->saveSlugsTo('slug'); } diff --git a/src/Models/PlanSubscription.php b/src/Models/PlanSubscription.php index df195f1..1ee4c58 100755 --- a/src/Models/PlanSubscription.php +++ b/src/Models/PlanSubscription.php @@ -79,7 +79,7 @@ class PlanSubscription extends Model 'user_type', 'plan_id', 'slug', - 'title', + 'name', 'description', 'trial_ends_at', 'starts_at', @@ -118,7 +118,7 @@ class PlanSubscription extends Model * @var array */ public $translatable = [ - 'title', + 'name', 'description', ]; @@ -148,7 +148,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plan_subscriptions')); $this->setRules([ - 'title' => 'required|string|max:150', + 'name' => 'required|string|max:150', 'description' => 'nullable|string|max:10000', 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_subscriptions').',slug', 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', @@ -185,7 +185,7 @@ public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('title') + ->generateSlugsFrom('name') ->saveSlugsTo('slug'); } diff --git a/src/Traits/HasSubscriptions.php b/src/Traits/HasSubscriptions.php index dc0aee2..63c5a21 100755 --- a/src/Traits/HasSubscriptions.php +++ b/src/Traits/HasSubscriptions.php @@ -97,7 +97,7 @@ public function newSubscription($subscription, Plan $plan): PlanSubscription $period = new Period($plan->invoice_interval, $plan->invoice_period, $trial->getEndDate()); return $this->subscriptions()->create([ - 'title' => $subscription, + 'name' => $subscription, 'plan_id' => $plan->getKey(), 'trial_ends_at' => $trial->getEndDate(), 'starts_at' => $period->getStartDate(), From e2410255453978912af210a161d20ef6a7e49cad Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 5 Apr 2018 19:54:39 +0200 Subject: [PATCH 10/20] Enforce consistency --- src/Models/Plan.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Models/Plan.php b/src/Models/Plan.php index 4263ce8..b8fdbbf 100755 --- a/src/Models/Plan.php +++ b/src/Models/Plan.php @@ -276,7 +276,7 @@ public function getFeatureBySlug(string $featureSlug): ?PlanFeature * * @return $this */ - public function activate() + public function makeActive() { $this->update(['is_active' => true]); @@ -288,7 +288,7 @@ public function activate() * * @return $this */ - public function deactivate() + public function makeInactive() { $this->update(['is_active' => false]); From 8e2dfd6970aed7dcf46e2198c4cd99814e10c028 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Mon, 9 Apr 2018 11:53:35 +0200 Subject: [PATCH 11/20] Convert timestamps into datetime fields and add timezone --- ...7_05_03_204353_create_plan_subscriptions_table.php | 11 ++++++----- ...03_204408_create_plan_subscription_usage_table.php | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php index 95347a8..e156e68 100755 --- a/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php +++ b/database/migrations/2017_05_03_204353_create_plan_subscriptions_table.php @@ -21,11 +21,12 @@ public function up(): void $table->string('slug'); $table->{$this->jsonable()}('name'); $table->{$this->jsonable()}('description')->nullable(); - $table->timestamp('trial_ends_at')->nullable(); - $table->timestamp('starts_at')->nullable(); - $table->timestamp('ends_at')->nullable(); - $table->timestamp('cancels_at')->nullable(); - $table->timestamp('canceled_at')->nullable(); + $table->dateTime('trial_ends_at')->nullable(); + $table->dateTime('starts_at')->nullable(); + $table->dateTime('ends_at')->nullable(); + $table->dateTime('cancels_at')->nullable(); + $table->dateTime('canceled_at')->nullable(); + $table->string('timezone')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/database/migrations/2017_05_03_204408_create_plan_subscription_usage_table.php b/database/migrations/2017_05_03_204408_create_plan_subscription_usage_table.php index a870649..9c9b538 100755 --- a/database/migrations/2017_05_03_204408_create_plan_subscription_usage_table.php +++ b/database/migrations/2017_05_03_204408_create_plan_subscription_usage_table.php @@ -19,7 +19,8 @@ public function up(): void $table->integer('subscription_id')->unsigned(); $table->integer('feature_id')->unsigned(); $table->smallInteger('used')->unsigned(); - $table->timestamp('valid_until')->nullable(); + $table->dateTime('valid_until')->nullable(); + $table->string('timezone')->nullable(); $table->timestamps(); $table->softDeletes(); From 9809d1be7f0927f68091b9ef4d31c9bb23bfa81a Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sun, 20 May 2018 07:39:13 +0200 Subject: [PATCH 12/20] Tweak validation rules --- src/Models/Plan.php | 6 +++--- src/Models/PlanFeature.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Models/Plan.php b/src/Models/Plan.php index b8fdbbf..3051264 100755 --- a/src/Models/Plan.php +++ b/src/Models/Plan.php @@ -183,11 +183,11 @@ public function __construct(array $attributes = []) 'signup_fee' => 'required|numeric', 'currency' => 'required|alpha|size:3', 'trial_period' => 'sometimes|integer|max:10000', - 'trial_interval' => 'sometimes|string|in:hour,day,week,month', + 'trial_interval' => 'sometimes|in:hour,day,week,month', 'invoice_period' => 'sometimes|integer|max:10000', - 'invoice_interval' => 'sometimes|string|in:hour,day,week,month', + 'invoice_interval' => 'sometimes|in:hour,day,week,month', 'grace_period' => 'sometimes|integer|max:10000', - 'grace_interval' => 'sometimes|string|in:hour,day,week,month', + 'grace_interval' => 'sometimes|in:hour,day,week,month', 'sort_order' => 'nullable|integer|max:10000000', 'prorate_day' => 'nullable|integer|max:150', 'prorate_period' => 'nullable|integer|max:150', diff --git a/src/Models/PlanFeature.php b/src/Models/PlanFeature.php index 58f2a60..d42d41c 100755 --- a/src/Models/PlanFeature.php +++ b/src/Models/PlanFeature.php @@ -146,7 +146,7 @@ public function __construct(array $attributes = []) 'description' => 'nullable|string|max:10000', 'value' => 'required|string', 'resettable_period' => 'sometimes|integer', - 'resettable_interval' => 'sometimes|string|in:hour,day,week,month', + 'resettable_interval' => 'sometimes|in:hour,day,week,month', 'sort_order' => 'nullable|integer|max:10000000', ]); } From 69a3d95cb12a27820639e9d7c59748e2aa6db37c Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Mon, 21 May 2018 21:58:27 +0200 Subject: [PATCH 13/20] Drop StyleCI multi-language support (paid feature now!) --- .styleci.yml | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 879f7f8..1baf2fb 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,33 +1,20 @@ -php: - preset: recommended +preset: recommended - enabled: - - dir_constant - - ereg_to_preg - - mb_str_functions - - no_short_echo_tag - - strict_comparison - - phpdoc_link_to_see - - no_php4_constructor - - declare_strict_types - - unalign_double_arrow - - length_ordered_imports - - modernize_types_casting - - return_type_declaration - - not_operator_with_successor_space +enabled: + - dir_constant + - ereg_to_preg + - mb_str_functions + - no_short_echo_tag + - strict_comparison + - phpdoc_link_to_see + - no_php4_constructor + - declare_strict_types + - unalign_double_arrow + - length_ordered_imports + - modernize_types_casting + - return_type_declaration + - not_operator_with_successor_space - disabled: - - align_double_arrow - - alpha_ordered_imports - -js: - tab-width: 4 - print-width: 120 - -ts: - tab-width: 4 - print-width: 120 - -css: - tab-width: 4 - print-width: 120 +disabled: + - align_double_arrow + - alpha_ordered_imports From a6c4b58baed2c3d97159142532ce4070692a5b83 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Mon, 21 May 2018 22:45:02 +0200 Subject: [PATCH 14/20] Update composer dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3a92df3..e29e81b 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "watson/validating": "^3.1.0" }, "require-dev": { - "codedungeon/phpunit-result-printer": "^0.6.0", + "codedungeon/phpunit-result-printer": "^0.19.0", "illuminate/container": "~5.6.0", "phpunit/phpunit": "^7.0.0" }, From 38bf4f03d18a8b96c9fb507c17ae80cb951db8f3 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 22 Jun 2018 19:44:42 +0200 Subject: [PATCH 15/20] Prepare and tweak testing configuration --- .travis.yml | 4 ++++ composer.json | 5 +++++ phpunit.xml.dist | 7 +++++-- tests/Integration/.gitkeep | 0 tests/Unit/.gitkeep | 0 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/Integration/.gitkeep create mode 100644 tests/Unit/.gitkeep diff --git a/.travis.yml b/.travis.yml index 496c612..aa4ca92 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,10 @@ env: - COMPOSER_FLAGS="--prefer-lowest" - COMPOSER_FLAGS="" +cache: + directories: + - $HOME/.composer/cache + before_script: - travis_retry composer self-update - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source diff --git a/composer.json b/composer.json index e29e81b..6d4c365 100644 --- a/composer.json +++ b/composer.json @@ -61,6 +61,11 @@ "Rinvex\\Subscriptions\\": "src" } }, + "autoload-dev": { + "psr-4": { + "Rinvex\\Subscriptions\\Tests\\": "tests" + } + }, "config": { "sort-packages": true, "preferred-install": "dist", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bc26f22..b20ef5b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,7 +15,10 @@ printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"> - tests + tests/Unit + + + tests/Integration @@ -26,7 +29,7 @@ - + diff --git a/tests/Integration/.gitkeep b/tests/Integration/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Unit/.gitkeep b/tests/Unit/.gitkeep new file mode 100644 index 0000000..e69de29 From 150b42eb6ee7eae4872227fec4b1b14d39291171 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 18 Jul 2018 23:14:03 +0200 Subject: [PATCH 16/20] Update StyleCI options --- .styleci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.styleci.yml b/.styleci.yml index 1baf2fb..336e5c3 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -3,17 +3,41 @@ preset: recommended enabled: - dir_constant - ereg_to_preg + - no_useless_else - mb_str_functions + - short_list_syntax - no_short_echo_tag - strict_comparison - phpdoc_link_to_see + - property_separation - no_php4_constructor + - php_unit_namespaced + - random_api_migration - declare_strict_types - unalign_double_arrow + - no_alternative_syntax + - standardize_increment - length_ordered_imports - modernize_types_casting + - non_printable_character - return_type_declaration + - explicit_string_variable + - no_unneeded_final_method + - no_unneeded_curly_braces + - blank_line_before_declare + - compact_nullable_typehint + - combine_consecutive_issets + - combine_consecutive_unsets + - explicit_indirect_variable + - ternary_to_null_coalescing + - escape_implicit_backslashes + - fully_qualified_strict_types + - phpdoc_return_self_reference + - no_null_property_initialization + - multiline_comment_opening_closing - not_operator_with_successor_space + - phpdoc_add_missing_param_annotation + - php_unit_set_up_tear_down_visibility disabled: - align_double_arrow From 3ffc2a3bf6e5d2ad4f302b992f0727dd0bf5fa4d Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 18 Jul 2018 21:14:35 +0000 Subject: [PATCH 17/20] Apply fixes from StyleCI --- src/Services/Period.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/Period.php b/src/Services/Period.php index 3907249..1480225 100755 --- a/src/Services/Period.php +++ b/src/Services/Period.php @@ -61,7 +61,7 @@ public function __construct($interval = 'month', $count = 1, $start = '') $start = clone $this->start; $method = 'add'.ucfirst($this->interval).'s'; - $this->end = $start->$method($this->period); + $this->end = $start->{$method}($this->period); } /** From 7d2c5261036fd17fef337f5fcbfa2fabfbb28425 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 20 Jul 2018 19:24:14 +0200 Subject: [PATCH 18/20] Update PHPUnit options --- phpunit.xml.dist | 18 +++++++++++++----- tests/{Integration => Feature}/.gitkeep | 0 2 files changed, 13 insertions(+), 5 deletions(-) rename tests/{Integration => Feature}/.gitkeep (100%) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b20ef5b..283a033 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,22 +15,30 @@ printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"> - tests/Unit + ./tests/Unit - - tests/Integration + + ./tests/Feature - src/ + ./src - + + + + + + + + + diff --git a/tests/Integration/.gitkeep b/tests/Feature/.gitkeep similarity index 100% rename from tests/Integration/.gitkeep rename to tests/Feature/.gitkeep From 8761c37492692db410d5208300899f8fd7cb561a Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 20 Jul 2018 19:24:30 +0200 Subject: [PATCH 19/20] Rename subscription model activation and deactivation methods --- src/Models/Plan.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Models/Plan.php b/src/Models/Plan.php index 3051264..58c712a 100755 --- a/src/Models/Plan.php +++ b/src/Models/Plan.php @@ -276,7 +276,7 @@ public function getFeatureBySlug(string $featureSlug): ?PlanFeature * * @return $this */ - public function makeActive() + public function activate() { $this->update(['is_active' => true]); @@ -288,7 +288,7 @@ public function makeActive() * * @return $this */ - public function makeInactive() + public function deactivate() { $this->update(['is_active' => false]); From e688b501379bcb2be2159eb161cf2d523bdd9e55 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 21 Sep 2018 16:52:16 +0400 Subject: [PATCH 20/20] Bump version --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66aaafd..9106ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](CONTRIBUTING.md). +## [v0.0.4] - 2018-09-21 +- Update travis php versions +- Define polymorphic relationship parameters explicitly +- Fix fully qualified booking unit methods (fix #20) +- Convert timestamps into datetime fields and add timezone +- Tweak validation rules +- Drop StyleCI multi-language support (paid feature now!) +- Update composer dependencies +- Prepare and tweak testing configuration +- Update StyleCI options +- Update PHPUnit options +- Rename subscription model activation and deactivation methods + ## [v0.0.3] - 2018-02-18 - Add PublishCommand to artisan - Move slug auto generation to the custom HasSlug trait @@ -34,5 +47,6 @@ This project adheres to [Semantic Versioning](CONTRIBUTING.md). ## v0.0.1 - 2017-06-29 - Tag first release +[v0.0.4]: https://github.com/rinvex/subscriptions/compare/v0.0.3...v0.0.4 [v0.0.3]: https://github.com/rinvex/subscriptions/compare/v0.0.2...v0.0.3 [v0.0.2]: https://github.com/rinvex/subscriptions/compare/v0.0.1...v0.0.2