37 lines
801 B
PHP
37 lines
801 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Juil;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
|
||
|
|
class PmisNoticeAttachment extends Model
|
||
|
|
{
|
||
|
|
protected $fillable = [
|
||
|
|
'notice_id',
|
||
|
|
'original_name',
|
||
|
|
'file_path',
|
||
|
|
'file_size',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function notice(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(PmisNotice::class, 'notice_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function formatSize(int $bytes): string
|
||
|
|
{
|
||
|
|
if ($bytes >= 1073741824) {
|
||
|
|
return round($bytes / 1073741824, 1).' G';
|
||
|
|
}
|
||
|
|
if ($bytes >= 1048576) {
|
||
|
|
return round($bytes / 1048576, 1).' M';
|
||
|
|
}
|
||
|
|
if ($bytes >= 1024) {
|
||
|
|
return round($bytes / 1024, 1).' K';
|
||
|
|
}
|
||
|
|
|
||
|
|
return $bytes.' B';
|
||
|
|
}
|
||
|
|
}
|