1. Go to this page and download the library: Download devravik/laravel-licensing 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/ */
// app/Models/User.php
use DevRavik\LaravelLicensing\Support\HasLicenses;
class User extends Authenticatable
{
use HasLicenses;
}
use DevRavik\LaravelLicensing\Facades\License;
$license = License::for($user)
->product('pro')
->seats(3)
->expiresInDays(365)
->create();
// The raw key is only available at creation time. Store or display it immediately.
$rawKey = $license->key;
use DevRavik\LaravelLicensing\Facades\License;
use DevRavik\LaravelLicensing\Exceptions\InvalidLicenseException;
use DevRavik\LaravelLicensing\Exceptions\LicenseExpiredException;
use DevRavik\LaravelLicensing\Exceptions\LicenseRevokedException;
try {
$license = License::validate($rawKey);
// Valid. Check grace period if needed:
if ($license->isInGracePeriod()) {
// Warn: expires in $license->graceDaysRemaining() days
}
} catch (LicenseExpiredException $e) {
// Expired beyond grace period
} catch (LicenseRevokedException $e) {
// Revoked
} catch (InvalidLicenseException $e) {
// Key not found
}
use DevRavik\LaravelLicensing\Facades\License;
use DevRavik\LaravelLicensing\Exceptions\SeatLimitExceededException;
try {
$activation = License::activate($rawKey, 'app.example.com');
} catch (SeatLimitExceededException $e) {
// All seats occupied
}
License::deactivate($rawKey, 'app.example.com');
License::revoke($rawKey);
$license = License::find($rawKey); // no exception on failure returns null
$license->isValid(); // not revoked and not fully expired
$license->isExpired(); // past expiration date
$license->isInGracePeriod(); // expired but within grace window
$license->isRevoked(); // revoked_at is set
$license->seatsRemaining(); // available activation slots
$license->graceDaysRemaining(); // days left in grace period
$license->activations; // Eloquent collection of current activations
// app/Models/Team.php
use DevRavik\LaravelLicensing\Support\HasLicenses;
class Team extends Model
{
use HasLicenses;
}
// Create a team license
$license = License::for($team)
->product('team-plan')
->seats(25)
->expiresInDays(365)
->create();
// All licenses for a user
$user->licenses;
// Active licenses for a product
$user->licenses()
->where('product', 'pro')
->whereNull('revoked_at')
->where(function ($q) {
$q->whereNull('expires_at')->orWhere('expires_at', '>', now());
})
->get();
// app/Models/License.php
namespace App\Models;
use DevRavik\LaravelLicensing\Models\License as BaseLicense;
class License extends BaseLicense
{
public function getIsPremiumAttribute(): bool
{
return in_array($this->product, ['pro', 'enterprise']);
}
}
'license_model' => \App\Models\License::class,
namespace App\Models;
use DevRavik\LaravelLicensing\Models\Activation as BaseActivation;
class Activation extends BaseActivation
{
// Add custom attributes or relationships
}