morphTo(); } public function getUrl() { $path = $this->document_path; return Storage::disk('public')->url($path); } public function getSize() { $path = $this->document_path; if (Storage::disk('public')->exists($path)) { $sizeInBytes = Storage::disk('public')->size($path); return round($sizeInBytes / 1024, 2) . " KB"; } return 0; } public function getExtension() { return pathinfo($this->document_path, PATHINFO_EXTENSION); } public function isImageFile() { $imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'tiff', 'tif', 'ico']; $extension = pathinfo($this->document_path, PATHINFO_EXTENSION); return in_array(Str::lower($extension), $imageExtensions); } protected function documentPath(): Attribute { return Attribute::make( get: function (mixed $value, array $attributes) { $collectionName = $attributes['collection_name']; $path = $attributes['document_path']; return "{$collectionName}/{$path}"; } ); } public function scopeActive($query, int $status = 1) { return $query->where('status', $status); } }