Skip to content

osenco/laravel-subscriptions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Subscriptions

Laravel subscription package

Installation

composer require osenco/subscriptions

Setup & configuration

php artisan vendor:publish --provider="Osen\Subscriptions\SubscriptionsServiceProvider"
php artisan migrate

// OR use the install command

php artisan subscriptions:install

Usage

Add trait to your user model

use Osen\Subscriptions\Concerns\HasSubscriptions;

class User extends Authenticatable
{
    use HasSubscriptions; // <- here
}

Create a plan

use Osen\Subscriptions\Models\SubscriptionPlan;

$plan = SubsriptionPlan::create([
    'name' => 'Basic',
    'description' => 'Basic plan',
    'price' => 1000,
    'interval' => 'month',
    'interval_count' => 1,
    'trial_period_days' => 30,
    'active' => true,
]);

OR use the Plan Facade

use Osen\Subscriptions\Facades\Plan;

...

Plan::called('Basic')
    ->describedAs('Basic plan')
    ->pricedAt(1000)
    ->interval('month') // or interval('months', 5)
    ->trialDays(30)
    ->active()
    ->save();

Subscribe a user to a plan

use Osen\Subscriptions\Facades\Subscription;
use Osen\Subscriptions\Facades\Subscribe;

$user = User::find(1);
$plan = Plan::find(1);

$subscription = $user->subscribeTo($plan, 1);

//OR use the Subscribe Facade for one or multiple users
$subscription = Subscribe::subscriber($user)->to($plan, 1);
$subscription = Subscribe::subscribers($userIds)->to($plan, 1);

Add grace period to subscription

$subscription = $user->subscribeTo($plan, 1)->gracePeriodDays(7);

About

Laravel subscription package

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages