'int', 'size' => 'int', 'include_in_pdf' => 'bool', ]; public static array $iconExt = [ 'default' => 'fa fa-file', 'pdf' => 'fa fa-file-pdf', 'jpg' => 'fa fa-file-image', 'jpeg' => 'fa fa-file-image', 'png' => 'fa fa-file-image', 'doc' => 'fa fa-file-word', 'docx' => 'fa fa-file-word', ]; public function version(): BelongsTo { return $this->belongsTo(OfferVersion::class, 'offer_version_id'); } public function getIconExt(): string { return self::$iconExt[$this->ext] ?? self::$iconExt['default']; } public function getURL(bool|string $do = false): string { return route('storage_file', [$this->id, 'offer', $do]); } public function getPath(): string { return \Storage::disk('offer')->path($this->dir . $this->filename); } public function formatBytes(int $precision = 2): string { $size = $this->size; if ($size <= 0) { return (string) $size; } $base = log($size) / log(1024); $suffixes = [' bytes', ' KB', ' MB', ' GB', ' TB']; return round(1024 ** ($base - floor($base)), $precision) . $suffixes[floor($base)]; } }