Download the PHP package jojostx/larasubs without Composer
On this page you can find all versions of the php package jojostx/larasubs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package larasubs
About
This package provides a straightforward interface to handle subscriptions and features consumption.
Considerations
- Payments are out of scope for this package.
- You may want to extend some of the core models, in case you need to override the logic behind some helper methods like
renew()
,cancel()
etc. E.g.: when cancelling a subscription you may want to also cancel the recurring payment attached.
Installation
You can install the package via composer:
Publish resources (config and migrations files):
Usage
To start using it, you just have to add the Jojostx\Larasubs\Models\Concerns\HasSubscriptions
trait to your User
model (or any model you want to have subscriptions):
And that's it!
Setting Plans Up
First things first, you have to define the plans you'll offer. In the example below, we are creating two plans.
Everything here is quite simple, but it is worth to emphasize: by receiving the interval options above, the two plans are defined as yearly with a 1 month trial period and grace period.
Trial Period
You can define a trial period for each plan, so your users will can access a plan on trial before the subscription starts:
Grace Period
You can define a grace period for each plan, so your users will not loose access to their features immediately when the subscription ends.
Setting Up Features
Next, you may define the features your plan will offer. In the example below, we are creating two features. In the example below, we are creating two features: one to handle how much minutes each user can spend with deploys and if they can use subdomains.
Associating Plans with Features
As each feature can belong to multiple plans (and they can have multiple features), you have to associate them:
It is necessary to pass a value to units
when associating a consumable feature with a plan.
In the example above, we are giving 15 minutes of deploy time to silver users and 25 to gold users. We are also allowing gold users to use subdomains.
Subscribing
Now that you have a set of plans with their own features, it is time to subscribe users to them. Registering subscriptions is quite simple:
In the example above, we are simulating an application that subscribes its users when their payments are approved. It is easy to see that the method subscribeTo
requires only two arguments:
- the plan the user is subscribing to.
- the unique name for the subscription.
There are other options you can pass to it to handle particular cases that we're gonna cover below.
By default, the
subscribeTo
method calculates the expiration considering the plan's 'Interval' options, so you don't have to worry about it.
Testing
Security Policy
If you discover any security related issues, please send an email instead of using the issue tracker.
Support
The following support channels are available at your fingertips:
- Chat on Slack
- Help on Email
- Follow on Twitter
License
This software is released under The MIT License (MIT).
(c) 2022 Jojostx, Some rights reserved.
All versions of larasubs with dependencies
illuminate/console Version ^8.0|^9.0
illuminate/contracts Version ^8.0|^9.0
illuminate/database Version ^8.0|^9.0
illuminate/support Version ^8.0|^9.0
spatie/eloquent-sortable Version ^4.0
spatie/laravel-schemaless-attributes Version ^2.3
spatie/laravel-sluggable Version ^3.4
spatie/laravel-translatable Version ^6.1