added full module support
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LicenseKey extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'company_id', 'key_hash', 'key_prefix', 'label', 'plan', 'max_users',
|
||||
'is_active', 'starts_at', 'expires_at', 'last_used_at', 'revoked_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'starts_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
'last_used_at' => 'datetime',
|
||||
'revoked_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public static function issueFor(Company $company, string $label, string $plan = 'standard', int $maxUsers = 10): string
|
||||
{
|
||||
$plainKey = 'WMS-' . Str::upper(Str::random(32));
|
||||
|
||||
self::create([
|
||||
'company_id' => $company->id,
|
||||
'key_hash' => hash('sha256', $plainKey),
|
||||
'key_prefix' => Str::substr($plainKey, 0, 12),
|
||||
'label' => $label,
|
||||
'plan' => $plan,
|
||||
'max_users' => $maxUsers,
|
||||
'is_active' => true,
|
||||
'starts_at' => now(),
|
||||
'expires_at' => now()->addYear(),
|
||||
]);
|
||||
|
||||
return $plainKey;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user