1. Go to this page and download the library: Download westel/laravel-license 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/ */
use Westel\License\Facades\License;
// Validate license (uses cache if available)
$result = License::validate();
if ($result['valid']) {
// License is valid
$features = $result['features'];
} else {
// Handle invalid license
return redirect()->route('license.invalid');
}
use Westel\License\Facades\License;
if (License::hasFeature('advanced_reports')) {
// Feature is available
}
// Check feature with limits
if (License::canUseFeature('api_calls', $currentUsage)) {
// Feature is within limits
}
// In routes/web.php
Route::middleware(['license.valid'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'index']);
});
// Protect specific features
Route::middleware(['license.feature:advanced_reports'])->group(function () {
Route::get('/reports', [ReportController::class, 'index']);
});
use Westel\License\Services\HardwareFingerprintService;
$fingerprint = app(HardwareFingerprintService::class)->generate();
// First validation (online) stores JWT token
License::validate();
// Subsequent validations use cached token
// Valid for configured offline_validation_days
License::validate(); // Uses offline token if server unreachable
use Westel\License\Services\LicenseService;
$licenseService = app(LicenseService::class);
// Validate feature with custom logic
$result = $licenseService->validateFeature('custom_feature', [
'current_usage' => 100,
'additional_data' => ['key' => 'value']
]);
if ($result['allowed']) {
// Proceed with feature
$remaining = $result['remaining'];
}
use Westel\License\Events\LicenseValidated;
use Westel\License\Events\LicenseExpired;
use Westel\License\Events\LicenseActivated;
// In EventServiceProvider
protected $listen = [
LicenseValidated::class => [
SendLicenseValidatedNotification::class,
],
LicenseExpired::class => [
NotifyLicenseExpired::class,
],
];
$license = License::find($licenseId);
if ($license->isExpired() && $license->isInGracePeriod()) {
// Show warning to user
$daysRemaining = $license->getGracePeriodDaysRemaining();
flash("Your license expired. {$daysRemaining} days remaining in grace period.");
}