PHP code example of rlaravel / plans

1. Go to this page and download the library: Download rlaravel/plans 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/ */

    

rlaravel / plans example snippets


'providers' => [
    /**
     * Third Party Service Providers...
     */
    RLaravel\Plans\Providers\PlansServiceProvider::class,
];

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use RLaravel\Plans\Contracts\PlanSubscriberInterface;
use RLaravel\Plans\Traits\PlanSubscriber;

class User extends Authenticatable implements PlanSubscriberInterface
{
    use PlanSubscriber;

use RLaravel\Plans\Models\Plan;
use RLaravel\Plans\Models\PlanFeature;

$plan = Plan::create([
    'name' => 'Pro',
    'description' => 'Pro plan',
    'price' => 9.99,
    'interval' => 'month',
    'interval_count' => 1,
    'trial_period_days' => 15,
    'sort_order' => 1,
]);

$plan->features()->saveMany([
    new PlanFeature(['code' => 'listings', 'value' => 50, 'sort_order' => 1]),
    new PlanFeature(['code' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]),
    new PlanFeature(['code' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10]),
    new PlanFeature(['code' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15])
]);

$feature = $plan->getFeatureByCode('pictures_per_listing');
$feature->value // Obtener el valor de la característica

use Auth;
use RLaravel\Plans\Models\Plan;

$user = Auth::user();
$plan = Plan::find(1);

$user->newSubscription('main', $plan)->create();

/**
 * Register the application services.
 *
 * @return void
 */
public function register()
{
    $this->app->bind(SubscriptionResolverInterface::class, CustomSubscriptionResolver::class);
}

$user->subscription('main')->ability()->canUse('listings');

$user->subscriptionUsage('main')->record('listings');

// Incremento por 2
$user->subscriptionUsage('main')->record('listings', 2);

// Anular con 9
$user->subscriptionUsage('main')->record('listings', 9, false);

// Reducir en 1
$user->subscriptionUsage('main')->reduce('listings');

// Reducir en 2
$user->subscriptionUsage('main')->reduce('listings', 2);

$user->subscriptionUsage('main')->clear();

$user->subscribed('main');
$user->subscribed('main', $planId); // Compruebe si la suscripción está activa Y utilizando un plan particular

$user->subscription('main')->isActive();
$user->subscription('main')->isCanceled();
$user->subscription('main')->isCanceledImmediately();
$user->subscription('main')->isEnded();
$user->subscription('main')->isOnTrial();

$user->subscription('main')->renew();

$user->subscription('main')->cancel();

$user->subscription('main')->cancel(true);

use RLaravel\Plans\Models\PlanSubscription;

// Obtenga suscripciones por plan:
$subscriptions = PlanSubscription::byPlan($plan_id)->get();

// Obtener suscripción por usuario:
$subscription = PlanSubscription::byUser($user_id)->first();

// Obtenga suscripciones con prueba que termina en 3 días:
$subscriptions = PlanSubscription::findEndingTrial(3)->get();

// Obtenga suscripciones con prueba finalizada:
$subscriptions = PlanSubscription::findEndedTrial()->get();

// Obtenga suscripciones con período que termina en 3 días:
$subscriptions = PlanSubscription::findEndingPeriod(3)->get();

// Obtenga suscripciones con período finalizado:
$subscriptions = PlanSubscription::findEndedPeriod()->get();
sh
$ php artisan migrate