PHP code example of osenco / subscriptions

1. Go to this page and download the library: Download osenco/subscriptions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

osenco / subscriptions example snippets


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,
]);

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);
bash
php artisan vendor:publish --provider="Osen\Subscriptions\SubscriptionsServiceProvider"
bash
php artisan migrate
bash
php artisan subscriptions:install