41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
final class SonarDeskRelease extends Model
|
|
{
|
|
protected $table = 'sonardesk_releases';
|
|
protected $fillable = [
|
|
'version', 'build_number', 'channel', 'minimum_macos', 'file_path',
|
|
'original_filename', 'file_size', 'sha256', 'sparkle_signature',
|
|
'release_notes', 'is_published', 'is_featured', 'published_at', 'download_count',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_published' => 'boolean',
|
|
'is_featured' => 'boolean',
|
|
'published_at' => 'datetime',
|
|
'file_size' => 'integer',
|
|
'download_count' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function scopePublished($query)
|
|
{
|
|
return $query->where('is_published', true)->whereNotNull('file_path')->whereNotNull('published_at');
|
|
}
|
|
|
|
public function getFormattedSizeAttribute(): string
|
|
{
|
|
$bytes = (int) $this->file_size;
|
|
if ($bytes < 1024) return $bytes.' B';
|
|
if ($bytes < 1048576) return number_format($bytes / 1024, 1).' KB';
|
|
if ($bytes < 1073741824) return number_format($bytes / 1048576, 1).' MB';
|
|
return number_format($bytes / 1073741824, 2).' GB';
|
|
}
|
|
}
|