Files
KarbonDatacenter/app/Models/SubmissionDocument.php
2026-06-24 20:32:14 +08:00

57 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class SubmissionDocument extends Model
{
use HasFactory;
protected $fillable = [
'submission_id',
'original_filename',
'stored_path',
'file_hash',
'mime_type',
'size',
'version',
'is_active',
'uploaded_by',
];
protected function casts(): array
{
return [
'is_active' => 'boolean',
'size' => 'integer',
'version' => 'integer',
];
}
public function submission(): BelongsTo
{
return $this->belongsTo(Submission::class);
}
public function uploadedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'uploaded_by');
}
public function humanSize(): string
{
$bytes = (int) $this->size;
if ($bytes >= 1048576) {
return round($bytes / 1048576, 2).' MB';
}
if ($bytes >= 1024) {
return round($bytes / 1024, 2).' KB';
}
return $bytes.' B';
}
}