@@ -57,25 +57,29 @@ That's it, we only have to use that trait in our User model! Now your users may
5757# ## Create a Plan
5858
5959` ` ` php
60- $plan = app(' rinvex.subscriptions.plan' )-> create([
60+ use Laravelcm\S ubscriptions\M odels\P lan;
61+ use Laravelcm\S ubscriptions\M odels\F eature;
62+ use Laravelcm\S ubscriptions\I nterval;
63+
64+ $plan = Plan::create([
6165 ' name' => ' Pro' ,
6266 ' description' => ' Pro plan' ,
6367 ' price' => 9.99,
6468 ' signup_fee' => 1.99,
6569 ' invoice_period' => 1,
66- ' invoice_interval' => ' month ' ,
70+ ' invoice_interval' => Interval::MONTH- > value ,
6771 ' trial_period' => 15,
68- ' trial_interval' => ' day ' ,
72+ ' trial_interval' => Interval::DAY- > value ,
6973 ' sort_order' => 1,
7074 ' currency' => ' USD' ,
7175]);
7276
7377// Create multiple plan features at once
7478$plan->features ()-> saveMany([
75- new PlanFeature ([' name' => ' listings' , ' value' => 50, ' sort_order' => 1]),
76- new PlanFeature ([' name' => ' pictures_per_listing' , ' value' => 10, ' sort_order' => 5]),
77- new PlanFeature ([' name' => ' listing_duration_days' , ' value' => 30, ' sort_order' => 10, ' resettable_period' => 1, ' resettable_interval' => ' month' ]),
78- new PlanFeature ([' name' => ' listing_title_bold' , ' value' => ' Y' , ' sort_order' => 15])
79+ new Feature ([' name' => ' listings' , ' value' => 50, ' sort_order' => 1]),
80+ new Feature ([' name' => ' pictures_per_listing' , ' value' => 10, ' sort_order' => 5]),
81+ new Feature ([' name' => ' listing_duration_days' , ' value' => 30, ' sort_order' => 10, ' resettable_period' => 1, ' resettable_interval' => ' month' ]),
82+ new Feature ([' name' => ' listing_title_bold' , ' value' => ' Y' , ' sort_order' => 15])
7983]);
8084` ` `
8185
@@ -84,7 +88,9 @@ $plan->features()->saveMany([
8488You can query the plan for further details, using the intuitive API as follows:
8589
8690` ` ` php
87- $plan = app(' rinvex.subscriptions.plan' )-> find(1);
91+ use Laravelcm\S ubscriptions\M odels\P lan;
92+
93+ $plan = Plan::find(1);
8894
8995// Get all plan features
9096$plan -> features;
@@ -109,23 +115,29 @@ Both `$plan->features` and `$plan->planSubscriptions` are collections, driven fr
109115Say you want to show the value of the feature _pictures_per_listing_ from above. You can do so in many ways:
110116
111117` ` ` php
118+ use Laravelcm\S ubscriptions\M odels\F eature;
119+ use Laravelcm\S ubscriptions\M odels\S ubscription;
120+
112121// Use the plan instance to get feature' s value
113122$amountOfPictures = $plan->getFeatureBySlug(' pictures_per_listing' )->value;
114123
115124// Query the feature itself directly
116- $amountOfPictures = app( ' rinvex.subscriptions.plan_feature ' )-> where(' slug' , ' pictures_per_listing' )->first()->value;
125+ $amountOfPictures = Feature:: where(' slug' , ' pictures_per_listing' )->first()->value;
117126
118127// Get feature value through the subscription instance
119- $amountOfPictures = app( ' rinvex.subscriptions.plan_subscription ' )-> find(1)->getFeatureValue(' pictures_per_listing' );
128+ $amountOfPictures = Subscription:: find(1)->getFeatureValue(' pictures_per_listing' );
120129```
121130
122131### Create a Subscription
123132
124133You can subscribe a user to a plan by using the `newSubscription()` function available in the `HasPlanSubscriptions` 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.
125134
126135` ` ` php
136+ use Laravelcm\S ubscriptions\M odels\P lan;
137+ use App\M odels\U ser;
138+
127139$user = User::find(1);
128- $plan = app( ' rinvex.subscriptions.plan ' )- > find(1);
140+ $plan = Plan:: find(1);
129141
130142$user -> newPlanSubscription(' main' , $plan );
131143` ` `
@@ -137,8 +149,11 @@ The first argument passed to `newSubscription` method should be the title of the
137149You can change subscription plan easily as follows:
138150
139151```php
140- $plan = app(' rinvex.subscriptions.plan' )->find(2);
141- $subscription = app(' rinvex.subscriptions.plan_subscription' )->find(1);
152+ use Laravelcm\Subscriptions\Models\Plan;
153+ use Laravelcm\Subscriptions\Models\Subscription;
154+
155+ $plan = Plan::find(2);
156+ $subscription = Subscription::find(1);
142157
143158// Change subscription plan
144159$subscription->changePlan($plan);
@@ -151,8 +166,10 @@ If both plans (current and new plan) have the same billing frequency (e.g., `inv
151166Plan features are great for fine-tuning subscriptions, you can top-up certain feature for X times of usage, so users may then use it only for that amount. Features also have the ability to be resettable and then it' s usage could be expired too. See the following examples:
152167
153168` ` ` php
169+ use Laravelcm\S ubscriptions\M odels\F eature;
170+
154171// Find plan feature
155- $feature = app( ' rinvex.subscriptions.plan_feature ' )- > where(' name' , ' listing_duration_days' )-> first();
172+ $feature = Feature:: where(' name' , ' listing_duration_days' )-> first();
156173
157174// Get feature reset date
158175$feature -> getResetDate(new \C arbon\C arbon());
@@ -263,24 +280,27 @@ $user->planSubscription('main')->cancel(true);
263280#### Subscription Model
264281
265282```php
283+ use Laravelcm\Subscriptions\Models\Subscription;
284+ use App\Models\User;
285+
266286// Get subscriptions by plan
267- $subscriptions = app( ' rinvex.subscriptions.plan_subscription ' )-> byPlanId($plan_id)->get();
287+ $subscriptions = Subscription:: byPlanId($plan_id)->get();
268288
269289// Get bookings of the given user
270- $user = \App\Models\ User::find(1);
271- $bookingsOfSubscriber = app( ' rinvex.subscriptions.plan_subscription ' )-> ofSubscriber($user)->get();
290+ $user = User::find(1);
291+ $bookingsOfSubscriber = Subscription:: ofSubscriber($user)->get();
272292
273293// Get subscriptions with trial ending in 3 days
274- $subscriptions = app( ' rinvex.subscriptions.plan_subscription ' )-> findEndingTrial(3)->get();
294+ $subscriptions = Subscription:: findEndingTrial(3)->get();
275295
276296// Get subscriptions with ended trial
277- $subscriptions = app( ' rinvex.subscriptions.plan_subscription ' )-> findEndedTrial()->get();
297+ $subscriptions = Subscription:: findEndedTrial()->get();
278298
279299// Get subscriptions with period ending in 3 days
280- $subscriptions = app( ' rinvex.subscriptions.plan_subscription ' )-> findEndingPeriod(3)->get();
300+ $subscriptions = Subscription:: findEndingPeriod(3)->get();
281301
282302// Get subscriptions with ended period
283- $subscriptions = app( ' rinvex.subscriptions.plan_subscription ' )-> findEndedPeriod()->get();
303+ $subscriptions = Subscription:: findEndedPeriod()->get();
284304```
285305
286306### Models
0 commit comments