PHP code example of masterix21 / laravel-licensing-client
1. Go to this page and download the library: Download masterix21/laravel-licensing-client 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/ */
masterix21 / laravel-licensing-client example snippets
use LucaLongo\LaravelLicensingClient\Facades\LaravelLicensingClient;
// Activate
LaravelLicensingClient::activate('LIC-XXXX-XXXX-XXXX-XXXX');
// Check validity (offline, from stored PASETO token)
LaravelLicensingClient::isValid();
// Validate with exception on failure
$claims = LaravelLicensingClient::validate();
// Get license info from token claims
$info = LaravelLicensingClient::getLicenseInfo();
// Returns: [
// 'license_id' => 1,
// 'license_key_hash' => 'sha256...',
// 'status' => 'active',
// 'max_usages' => 5,
// 'expires_at' => '2027-01-07T00:00:00+00:00',
// 'issued_at' => '2027-01-01T00:00:00+00:00',
// 'license_expires_at' => '2027-12-31T23:59:59+00:00',
// 'force_online_after' => '2027-01-14T00:00:00+00:00',
// 'grace_until' => null,
// 'usage_fingerprint' => 'sha256...',
// ]
// Check expiration warnings
LaravelLicensingClient::isExpiringSoon(7);
// Check if online refresh is
use LucaLongo\LaravelLicensingClient\LaravelLicensingClient;
class LicenseController extends Controller
{
public function status(LaravelLicensingClient $licensing)
{
return response()->json([
'valid' => $licensing->isValid(),
'info' => $licensing->getLicenseInfo(),
'
// Single route
Route::get('/dashboard', DashboardController::class)->middleware('license');
// Route group
Route::middleware('license')->group(function () {
Route::get('/reports', ReportsController::class);
Route::get('/analytics', AnalyticsController::class);
});
public function dashboard(Request $request)
{
if ($request->attributes->get('license_expiring_soon')) {
$expiresAt = $request->attributes->get('license_expires_at');
// Show renewal warning
}
}
// Check if in grace period
LaravelLicensingClient::isInGracePeriod();
// Manually start (useful for testing)
LaravelLicensingClient::startGracePeriod();
use LucaLongo\LaravelLicensingClient\Services\FingerprintGenerator;
class CustomFingerprintGenerator extends FingerprintGenerator
{
public function generate(): string
{
$components = [
$this->getHostname(),
$this->getMachineId(),
config('app.deployment_id'),
];
return hash('sha256', implode('|', array_filter($components)));
}
}
// Register in a service provider
$this->app->bind(FingerprintGenerator::class, CustomFingerprintGenerator::class);
use LucaLongo\LaravelLicensingClient\Exceptions\LicensingException;
try {
LaravelLicensingClient::validate();
} catch (LicensingException $e) {
// Possible messages:
// - "The provided license key is invalid."
// - "The license has expired."
// - "The license has not been activated."
// - "The license has been suspended."
// - "The license has been cancelled."
// - "Device fingerprint does not match the licensed device."
// - "The fingerprint is already in use by another device."
// - "License usage limit has been exceeded."
// - "Offline tokens are not enabled for this license."
// - "Too many requests to the licensing server. Please try again later."
// - "Online verification is
use Illuminate\Support\Facades\Http;
use LucaLongo\LaravelLicensingClient\Facades\LaravelLicensingClient;
public function test_protected_route(): void
{
Http::fake([
'*/api/licensing/v1/activate' => Http::response([
'success' => true,
'data' => [
'token' => 'v4.public.test-token...',
'license' => ['id' => 'ulid', 'status' => 'active'],
],
]),
]);
LaravelLicensingClient::activate('TEST-KEY');
$this->get('/protected-route')->assertStatus(200);
}