koel/app/Models/License.php

47 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2024-01-05 16:42:50 +00:00
<?php
namespace App\Models;
use App\Casts\EncryptedValueCast;
use App\Casts\LicenseInstanceCast;
use App\Casts\LicenseMetaCast;
use App\Values\LicenseInstance;
use App\Values\LicenseMeta;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2024-01-05 16:42:50 +00:00
use Illuminate\Database\Eloquent\Model;
2024-01-10 00:47:09 +00:00
use Illuminate\Support\Str;
2024-01-05 16:42:50 +00:00
/**
* @property-read string $short_key
* @property string $key
* @property LicenseInstance $instance An activation of the license.
* @see https://docs.lemonsqueezy.com/api/license-key-instances
* @property LicenseMeta $meta
* @property-read Carbon $activated_at
*/
class License extends Model
{
use HasFactory;
2024-01-05 16:42:50 +00:00
protected $guarded = ['id'];
protected $casts = [
'key' => EncryptedValueCast::class,
'instance' => LicenseInstanceCast::class,
'meta' => LicenseMetaCast::class,
'expires_at' => 'datetime',
];
protected function shortKey(): Attribute
{
2024-10-06 19:21:30 +00:00
return Attribute::get(fn (): string => '****-' . Str::afterLast($this->key, '-'))->shouldCache();
2024-01-05 16:42:50 +00:00
}
protected function activatedAt(): Attribute
{
2024-10-06 19:21:30 +00:00
return Attribute::get(fn () => $this->instance->createdAt)->shouldCache();
2024-01-05 16:42:50 +00:00
}
}