Skip to content

Media ​

File: src/Entities/Media.php
Namespace: Unusualify\Modularous\Entities
Extends: Model
Traits: HasFactory, HasCreator

Represents an uploaded image in the media library. Stores dimensions, alt text, captions, and supports configurable extra metadata fields. Provides formatted output for frontend media pickers and integrates with the Glide image transformation service.

Fillable Attributes ​

AttributeTypeDescription
uuidstringUUID-based storage path
filenamestringOriginal filename
alt_textstringAlt text for accessibility
captionstringImage caption
widthintImage width in pixels
heightintImage height in pixels

Additional fields from modularous.media_library.extra_metadatas_fields config are merged into fillable at construction time.

Accessors ​

AccessorTypeDescription
dimensionsstring"{width}x{height}"

Methods ​

scopeUnused($query) ​

Returns all media records not referenced in the mediables pivot table.

canDeleteSafely(): bool ​

Returns true when the media is not referenced by any model.

isReferenced(): bool ​

Returns true when the media is used by at least one model.

mediableFormat(): array ​

Formats the image for the frontend media picker with thumbnail, medium, and original URLs, dimensions, tags, and CRUD action URLs.

getMetadata($name, $fallback = null): mixed ​

Retrieves metadata from the mediable pivot, respecting locale fallback for translatable metadata fields.

replace($fields): void ​

Updates the media record and recalculates crop coordinates in all referencing mediables rows when dimensions change.

altTextFrom($filename): string ​

Generates alt text from a filename by stripping extensions and @2x suffixes, then converting to title case.

delete(): bool ​

Only deletes if the media can be deleted safely (not referenced). Returns false otherwise.