1. Go to this page and download the library: Download turahe/subscription 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/ */
turahe / subscription example snippets
namespace App\Models;
use Turahe\Subscription\Traits\HasPlanSubscriptions;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasPlanSubscriptions;
}
use Turahe\Subscription\Models\Plan;
use Turahe\Subscription\Models\PlanFeature;
use Turahe\Subscription\Interval;
$plan = Plan::create([
'name' => 'Pro',
'description' => 'Pro plan',
'price' => 9.99,
'signup_fee' => 1.99,
'invoice_period' => 1,
'invoice_interval' => Interval::MONTH->value,
'trial_period' => 15,
'trial_interval' => Interval::DAY->value,
'sort_order' => 1,
'currency' => 'USD',
]);
// Create multiple plan features at once
$plan->features()->saveMany([
new PlanFeature(['name' => 'listings', 'value' => 50, 'sort_order' => 1]),
new PlanFeature(['name' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]),
new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']),
new PlanFeature(['name' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15])
]);
use Turahe\Subscription\Models\Plan;
$plan = Plan::find(1);
// Get all plan features
$plan->features;
// Get all plan subscriptions
$plan->subscriptions;
// Check if the plan is free
$plan->isFree();
// Check if the plan has trial period
$plan->hasTrial();
// Check if the plan has grace period
$plan->hasGrace();
use Turahe\Subscription\Models\PlanFeature;
use Turahe\Subscription\Models\PlanSubscription;
// Use the plan instance to get feature's value
$amountOfPictures = $plan->getFeatureBySlug('pictures_per_listing')->value;
// Query the feature itself directly
$amountOfPictures = PlanFeature::where('slug', 'pictures_per_listing')->first()->value;
// Get feature value through the subscription instance
$amountOfPictures = PlanSubscription::find(1)->getFeatureValue('pictures_per_listing');
use Turahe\Subscription\Models\Plan;
use Turahe\Subscription\Models\PlanSubscription;
$plan = Plan::find(2);
$subscription = PlanSubscription::find(1);
// Change subscription plan
$subscription->changePlan($plan);
use Turahe\Subscription\Models\PlanFeature;
// Find plan feature
$feature = PlanFeature::where('name', 'listing_duration_days')->first();
// Get feature reset date
$feature->getResetDate(new \Carbon\Carbon());
use Turahe\Auth\Models\User;use Turahe\Subscription\Models\PlanSubscription;
// Get subscriptions by plan
$subscriptions = PlanSubscription::byPlanId($plan_id)->get();
// Get bookings of the given user
$user = User::find(1);
$bookingsOfSubscriber = PlanSubscription::ofSubscriber($user)->get();
// Get subscriptions with trial ending in 3 days
$subscriptions = PlanSubscription::findEndingTrial(3)->get();
// Get subscriptions with ended trial
$subscriptions = PlanSubscription::findEndedTrial()->get();
// Get subscriptions with period ending in 3 days
$subscriptions = PlanSubscription::findEndingPeriod(3)->get();
// Get subscriptions with ended period
$subscriptions = PlanSubscription::findEndedPeriod()->get();