PHP code example of cryptodev4 / laravel-subscriptions
1. Go to this page and download the library: Download cryptodev4/laravel-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/ */
cryptodev4 / laravel-subscriptions example snippets
namespace App\Models;
use CryptoDev4\LaravelSubscriptions\Traits\HasPlanSubscriptions;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasPlanSubscriptions;
}
$plan = Plan::find(1);
// Get all plan features
$plan->features;
// Get all plan subscriptions
$plan->planSubscriptions;
// 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
$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');
// Find plan feature
$feature = PlanFeature::where('name', 'listing_duration_days')->first();
// Get feature reset date
$feature->getResetDate(new \Carbon\Carbon());
// Get subscriptions by plan
$subscriptions = PlanSubcription::byPlanId($plan_id)->get();
// Get bookings of the given user
$user = \App\Models\User::find(1);
$bookingsOfSubscriber = PlanSubcription::ofSubscriber($user)->get();
// Get subscriptions with trial ending in 3 days
$subscriptions = PlanSubcription::findEndingTrial(3)->get();
// Get subscriptions with ended trial
$subscriptions = PlanSubcription::findEndedTrial()->get();
// Get subscriptions with period ending in 3 days
$subscriptions = PlanSubcription::findEndingPeriod(3)->get();
// Get subscriptions with ended period
$subscriptions = PlanSubcription::findEndedPeriod()->get();