2023-11-01 16:58:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class License extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
2024-02-23 11:54:12 +01:00
|
|
|
|
2024-07-04 17:21:36 +02:00
|
|
|
public const STATUS_ACTIVE = 'active';
|
2024-02-23 11:54:12 +01:00
|
|
|
public const STATUS_INACTIVE = 'inactive';
|
2023-11-01 16:58:10 +01:00
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'license_key',
|
|
|
|
|
'user_id',
|
|
|
|
|
'license_provider',
|
|
|
|
|
'status',
|
2024-02-23 11:54:12 +01:00
|
|
|
'meta',
|
2023-11-01 16:58:10 +01:00
|
|
|
];
|
|
|
|
|
|
2024-06-10 16:10:14 +02:00
|
|
|
protected function casts()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'meta' => 'array',
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-11-01 16:58:10 +01:00
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 17:21:36 +02:00
|
|
|
public function isActive()
|
|
|
|
|
{
|
|
|
|
|
return $this->status === self::STATUS_ACTIVE;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-01 16:58:10 +01:00
|
|
|
public function scopeActive($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', self::STATUS_ACTIVE);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-12 11:57:13 +01:00
|
|
|
public function getMaxFileSizeAttribute(): int
|
2023-11-01 16:58:10 +01:00
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
1 => 25000000, // 25 MB,
|
|
|
|
|
2 => 50000000, // 50 MB,
|
|
|
|
|
3 => 75000000, // 75 MB,
|
|
|
|
|
][$this->meta['tier']];
|
|
|
|
|
}
|
2023-11-29 14:53:08 +01:00
|
|
|
|
2023-12-12 11:57:13 +01:00
|
|
|
public function getCustomDomainLimitCountAttribute(): ?int
|
2023-11-29 14:53:08 +01:00
|
|
|
{
|
|
|
|
|
return [
|
2023-12-03 15:31:34 +01:00
|
|
|
1 => 1,
|
|
|
|
|
2 => 10,
|
2023-11-29 14:53:08 +01:00
|
|
|
3 => null,
|
|
|
|
|
][$this->meta['tier']];
|
|
|
|
|
}
|
2023-12-03 15:02:48 +01:00
|
|
|
|
2024-07-04 17:21:36 +02:00
|
|
|
public function getMaxUsersLimitCountAttribute(): ?int
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
1 => 1,
|
|
|
|
|
2 => 5,
|
2024-07-17 12:13:03 +02:00
|
|
|
3 => 10,
|
2024-07-04 17:21:36 +02:00
|
|
|
][$this->meta['tier']];
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-03 15:02:48 +01:00
|
|
|
public static function booted(): void
|
|
|
|
|
{
|
|
|
|
|
static::saved(function (License $license) {
|
|
|
|
|
if ($license->user) {
|
|
|
|
|
$license->user->flushCache();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
static::deleted(function (License $license) {
|
|
|
|
|
if ($license->user) {
|
|
|
|
|
$license->user->flushCache();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-11-01 16:58:10 +01:00
|
|
|
}
|