Laravel subscription package
composer require osenco/subscriptions
php artisan vendor:publish --provider="Osen\Subscriptions\SubscriptionsServiceProvider"
php artisan migrate
// OR use the install command
php artisan subscriptions:install
use Osen\Subscriptions\Concerns\HasSubscriptions;
class User extends Authenticatable
{
use HasSubscriptions; // <- here
}
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();
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);
$subscription = $user->subscribeTo($plan, 1)->gracePeriodDays(7);