PHP code example of rabol / laravel-simple-subscription
1. Go to this page and download the library: Download rabol/laravel-simple-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/ */
rabol / laravel-simple-subscription example snippets
return [
];
namespace App\Models;
use Rabol\SimpleSubscription\Traits\HasSubscriptions;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasSubscriptions;
}
$plan = SimpleSubscriptionPlan::find(1);
or
$plan = SimpleSubscriptionPlan::whereName('My cool subscription')->first();
// 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 the plan instance to get feature's value
$myCoolFeatureValue = $plan->getFeatureByName('My Cool feature')->value;
// Get the usage of the feature you can
$myCoolFeatureUsage = SimpleSubscriptionPlanFeature::wherePlanId(1)->whereName('Feature 1')->first()->usage()->first()->used;
// Get subscriptions by plan
$subscriptions = SimpleSubscriptionPlanSubscription::byPlanId($plan_id)->get();
// Get bookings of the given user
$user = \App\Models\User::find(1);
$bookingsOfUser = SimpleSubscriptionPlanSubscription::ofSubscriber($user)->get();
// Get subscriptions with trial ending in 3 days
$subscriptions = SimpleSubscriptionPlanSubscription::findEndingTrial(3)->get();
// Get subscriptions with ended trial
$subscriptions = SimpleSubscriptionPlanSubscription::findEndedTrial()->get();
// Get subscriptions with period ending in 3 days
$subscriptions = SimpleSubscriptionPlanSubscription::findEndingPeriod(3)->get();
// Get subscriptions with ended period
$subscriptions = SimpleSubscriptionPlanSubscription::findEndedPeriod()->get();