'int', 'size' => 'int' ]; protected $fillable = [ 'user_id', 'identifier', 'filename', 'dir', 'original_name', 'ext', 'mine', 'size' ]; public function user() { return $this->belongsTo(User::class); } public function formatBytes($precision = 2) { $size = $this->size; if ($size > 0) { $size = (int) $size; $base = log($size) / log(1024); $suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB'); return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; } else { return $size; } } }