Laravel License Key System Apr 2026
$licenseKey = $request->header('X-License-Key') ?? config('app.license_key'); if (!$licenseKey) return response()->json(['error' => 'License key required'], 401);
$activeDomains = $license->activations() ->where('domain', $domain) ->orWhere('domain', '!=', $domain) ->count();
Create CheckLicense middleware:
if ($activeDomains >= $license->max_domains) // allow if this domain is already activated return $license->activations()->where('domain', $domain)->exists();
Route::post('/license/verify', function (Request $request) $request->validate([ 'license_key' => 'required); laravel license key system
if (!$result['valid']) return response()->json(['error' => $result['message']], 403);
// Example: "PROD-ABCD-EFGH-IJKL-MNOP"
php artisan make:command LicenseExpiryCheck // inside handle() License::where('valid_until', '<', now()) ->where('status', 'active') ->update(['status' => 'expired']); Schedule it in Console/Kernel :
return $next($request);
protected function checkDomainLimit(License $license, string $domain): bool