Installation
composer require getkeymanager/laravel-sdk
The package auto-discovers the service provider (no manual registration needed).
Publish Configuration
php artisan vendor:publish --provider="KeyManager\LaravelSdk\KeyManagerServiceProvider" --tag="config"
Edit config/keymanager.php with your API key and environment settings.
First Validation Check
use KeyManager\Facades\KeyManager;
if (!KeyManager::validate()) {
abort(403, 'License validation failed');
}
Middleware Protection
Add to app/Http/Kernel.php:
'web' => [
\KeyManager\LaravelSdk\Http\Middleware\ValidateLicense::class,
// ...
],
Protect a route with license validation:
Route::middleware(['web', 'validate.license'])->group(function () {
Route::get('/premium', [PremiumController::class, 'index']);
});
if (KeyManager::validate()) {
// Valid license
}
KeyManager::validate(['offline' => true]); // Uses cached license
Route::middleware(['feature:analytics'])->group(...);
if (KeyManager::featureEnabled('analytics')) {
// Enable feature
}
php artisan keymanager:activate --license=YOUR_LICENSE_KEY
KeyManager::activate('YOUR_LICENSE_KEY');
Leverage environment-specific configs:
// config/keymanager.php
'environments' => [
'local' => [
'api_key' => env('KEYMANAGER_LOCAL_API_KEY'),
],
'production' => [
'api_key' => env('KEYMANAGER_API_KEY'),
],
],
Combine with Laravel’s built-in middleware:
Route::middleware(['auth', 'validate.license', 'throttle:60'])->group(...);
Enable logging in config/keymanager.php:
'logging' => true,
Logs appear in storage/logs/keymanager.log.
Automatically caches license validation results per session. Disable with:
KeyManager::validate(['cache' => false]);
php artisan keymanager:status
php artisan keymanager:deactivate
Offline Validation Quirks
offline: true) relies on cached data. Ensure cache:config is enabled.php artisan cache:clear if offline checks fail unexpectedly.Middleware Caching
validate.license middleware caches validation results. Override with:
KeyManager::validate(['cache' => false]);
Environment Mismatch
environments config, ensure APP_ENV matches your config keys.config('keymanager.environment') in Tinker.Rate Limiting
throttle if needed:
Route::middleware(['throttle:60,1'])->group(...);
Enable Verbose Logging
KeyManager::setLogLevel(\Monolog\Logger::DEBUG);
Check License Response
$response = KeyManager::validate(['debug' => true]);
dd($response->getOriginalContent());
Validate API Key Test connectivity with:
php artisan keymanager:status --verbose
Custom Validation Logic Extend the validator:
KeyManager::extendValidator(function ($license) {
return $license['custom_field'] === 'expected_value';
});
Event Listeners Listen for license events:
KeyManager::listen('license.validated', function ($license) {
// Custom logic
});
Override Middleware Publish and modify the middleware:
php artisan vendor:publish --tag="keymanager.middleware"
Edit app/Http/Middleware/ValidateLicense.php.
Custom Artisan Commands Extend the SDK’s commands:
KeyManager::extendCommand('keymanager:custom', function () {
// Custom logic
});
How can I help you explore Laravel packages today?