PHP code example of whilesmart / eloquent-entitlements

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

    

whilesmart / eloquent-entitlements example snippets


$entitlements = app(Entitlements::class);

$entitlements->allows($owner, 'reports');      // bool
$entitlements->check($owner, 'reports');       // AccessResult: allowed + why not
$entitlements->limit($owner, 'seats');         // ?int, null = unlimited
$entitlements->remaining($owner, 'api_calls'); // int|float
$entitlements->consume($owner, 'api_calls', 1);

Route::middleware('feature:reports')->group(function () {
    // ...
});

use Whilesmart\Entitlements\Contracts\OwnerResolver;

$this->app->bind(OwnerResolver::class, WorkspaceOwnerResolver::class);

$this->app->bind(Entitlements::class, PlanEntitlements::class);

use Whilesmart\Entitlements\Traits\HasEntitlements;

class Workspace extends Model
{
    use HasEntitlements;
}

$workspace->entitledTo('reports'); // delegates to the bound Entitlements
$workspace->limitFor('seats');
$workspace->activeSubscription();

public function resolve(?Model $owner): ?ResolvedPlan;

$this->app->bind(PlanSource::class, MyConfigPlanSource::class);

$this->app->bind(UsageMeter::class, MyRedisMeter::class);

app(CouponService::class)->redeem($coupon, $owner);

$passes = app(\Whilesmart\Entitlements\Services\FreePassService::class);

$pass = $passes->grant($owner, $plan, until: now()->addMonth());
$passes->all();
$passes->stop($pass->id);