Download the PHP package tsrgtm/media-library without Composer
On this page you can find all versions of the php package tsrgtm/media-library. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tsrgtm/media-library
More information about tsrgtm/media-library
Files in tsrgtm/media-library
Package media-library
Short Description Advanced Laravel media library and Filament 5 plugin with a reusable media picker field, resumable uploads, folders, tags, responsive images and rich previews.
License MIT
Homepage https://github.com/tsrgtm/media-library
Informations about the package media-library
tsrgtm/media-library
A high-performance, enterprise-grade Laravel media library and Google Drive-style Filament 5 workspace. Built by Tusar Gautam, featuring TUS resumable uploads with multi-file concurrency, zero-migration polymorphic model attachments, dynamic WebP responsive conversions, folder hierarchies, tag management, trash bin soft-deletes, static placeholder caching, and rich previews for documents, video, audio, code, and spreadsheets.
Table of Contents
- Key Features
- Zero Schema Hassle
- Requirements
- Installation & Setup
- Package Management Commands
- 1. Installing the Package (
media-library:install) - 2. Updating Assets & Migrations (
media-library:update) - 3. Uninstalling & Reverting Changes (
media-library:uninstall)
- 1. Installing the Package (
- Tailwind CSS & Styling Setup
- Filament Panel & Plugin Customization
- Model Configuration (
HasMediaTrait)- 1. Adding Trait to Models
- 2. Attaching, Syncing, and Detaching Media
- 3. Retrieving Media & Collections
- 4. Replacing Media
- Filament Media Picker Form Component
- 1. Single File Picker
- 2. Multi-File Picker with Reordering
- 3. Filtering by Kinds, Extensions, and MIME Types
- 4. Default Folder & Custom Pivot Properties
- 5. Component Options Reference
- Placeholder Caching & Performance
- Resumable TUS Uploads & Queue Processing
- API Controllers & Routes
- Configuration Reference
- Testing
- License
Key Features
- 🔗 Zero Database Schema Hassle: Attach single or multiple media items to any model using polymorphic relations — no database columns, foreign keys, or migrations needed on your tables.
- 🛠️ Complete Lifecycle Commands: Includes
media-library:install,media-library:update, andmedia-library:uninstallto install, upgrade, or cleanly revert all changes without errors. - 📁 Google Drive-Style Workspace: Full-page Filament 5 panel interface with grid/list view toggles, marquee item selection, drag-and-drop folder moving, and path breadcrumbs.
- ⚙️ Fully Customizable Plugin: Easily customize navigation icon, menu group, sort order, page label, and URL slugs directly on the plugin instance.
- 🎨 Self-Sufficient CSS & Tailwind v4: Includes standalone Tailwind CSS directives so component UI renders cleanly out-of-the-box.
- ⚡ TUS Resumable Uploads: Multi-file chunked upload engine supporting up to 4 concurrent streams with auto-resume on network failure.
- 🖼️ Responsive Image Engine: Automatic WebP generation with configurable width breakpoints (
thumbnail,small,medium,large). - 🚀 Static Placeholder Caching: In-memory memoization of SVG/PNG placeholder URLs to eliminate repetitive config and asset resolution during bulk media serialization.
- 🏷️ Tag & Folder Hierarchy: Nested folder organization with soft-delete cascade and dynamic tag management.
- ♻️ Trash Bin & Soft Deletes: Two-stage deletion with restore and permanent force-delete capabilities.
- 🔄 In-Place File Replacement: Update media contents while preserving original URLs and database model relationships.
- 👁️ Rich Media Lightbox Previews: Built-in visualizers for Images, Videos, Audio, PDF, DOCX, XLSX, Markdown, and Source Code syntax highlighting.
Zero Schema Hassle
[!IMPORTANT] No database changes required for your models!
You do NOT need to create any columns (such asfeatured_image_id,media_id, orgallery_ids) or write any database migrations for yourposts,products,users, orcategoriestables.
tsrgtm/media-library manages all attachments through a central, highly-optimized polymorphic mediables table.
Requirements
- PHP:
^8.3 - Laravel:
^12.0or^13.0 - Filament:
^5.0 - Livewire:
^4.0
Installation & Setup
1. Require via Composer
2. Run Package Installer
Run the automated installer command:
This command automatically:
- Publishes configuration (
config/media-library.php) - Publishes placeholder icon assets (
public/images/media-placeholders) - Publishes database migrations
- Publishes frontend assets
- Installs NPM dependencies (
tus-js-client,video.js,pdfjs-dist,docx-preview,xlsx,marked,highlight.js) - Auto-registers the Filament plugin in your Panel Provider
3. Run Migrations
4. Build Frontend Assets
Package Management Commands
1. Installing the Package (media-library:install)
Options:
--force: Overwrite existing published frontend source files.--no-npm: Skip automatic NPM dependency installation.--panel-provider=path: Custom path to your Filament panel provider (default:app/Providers/Filament/AdminPanelProvider.php).
2. Updating Assets & Migrations (media-library:update)
When upgrading tsrgtm/media-library to a new release, run the update command to sync updated JS/CSS assets, replace modified files, and run pending database migrations:
Options:
--force: Force overwrite all published frontend assets and configuration files.
3. Uninstalling & Reverting Changes (media-library:uninstall)
To completely revert all changes made by the package cleanly without leaving orphaned code or throwing errors:
This command automatically:
- Unregisters
MediaLibraryPluginfrom your Filament Panel Provider. - Reverts patches in
resources/js/app.jsand Filamenttheme.css. - Deletes published JS/CSS vendor assets and placeholder images.
- Drops package database tables (
media,media_folders,mediables,media_tags,media_upload_sessions) and deletesconfig/media-library.php. - Clears optimization caches.
Options:
--keep-data: Reverts code integration and published assets while preserving database tables and uploaded files.--force: Runs uninstall without interactive prompts.
After running uninstall, complete package removal via Composer:
Tailwind CSS & Styling Setup
Self-Sufficient CSS (Zero Configuration)
The package ships with self-sufficient CSS in resources/css/media-library.css containing standalone Tailwind CSS directives. Component styles render cleanly out of the box without requiring manual CSS edits.
Custom Filament Theme Configuration
If you are compiling a custom Filament Tailwind CSS theme (e.g. resources/css/filament/admin/theme.css), add the package @source directives so Vite scans package views during build:
Filament Panel & Plugin Customization
Register the MediaLibraryPlugin inside your Filament Panel Provider (e.g., app/Providers/Filament/AdminPanelProvider.php).
You can customize navigation group, icon, label, sort position, and URL slug directly on the plugin builder:
Model Configuration (HasMedia Trait)
1. Adding Trait to Models
Simply include the HasMedia trait in any Eloquent model. No database columns or migrations are needed!
2. Attaching, Syncing, and Detaching Media
Use the trait methods to link Media records to model instances seamlessly:
3. Retrieving Media & Collections
4. Replacing Media
To swap an existing collection's media with a new file:
Filament Media Picker Form Component
The package includes an interactive MediaPicker form field for Filament resources and forms.
[!NOTE]
MediaPickerautomatically hydrates its state from your model's media collection and automatically saves relationship attachments on form submission. You do not need a matching column on your database table.
1. Single File Picker
2. Multi-File Picker with Reordering
3. Filtering by Kinds, Extensions, and MIME Types
Limit what files users can select or upload in the modal:
4. Default Folder & Custom Pivot Properties
5. Component Options Reference
| Method | Type | Description | Default |
|---|---|---|---|
collection(string \| Closure) |
static |
Sets the pivot collection identifier. | 'default' |
multiple(bool \| Closure) |
static |
Allows selecting multiple media files. | false |
minItems(int \| Closure) |
static |
Minimum required items when multiple. | null |
maxItems(int \| Closure) |
static |
Maximum allowed items when multiple. | null |
acceptedKinds(array \| string) |
static |
Restrict selection by kinds (image, video, audio, document, archive). |
[] |
images() |
static |
Convenient shortcut for acceptedKinds(['image']). |
- |
videos() |
static |
Convenient shortcut for acceptedKinds(['video']). |
- |
audio() |
static |
Convenient shortcut for acceptedKinds(['audio']). |
- |
documents() |
static |
Convenient shortcut for acceptedKinds(['document']). |
- |
archives() |
static |
Convenient shortcut for acceptedKinds(['archive']). |
- |
acceptedExtensions(array) |
static |
Restrict by extension list (e.g. ['png', 'jpg', 'pdf']). |
[] |
acceptedMimeTypes(array) |
static |
Restrict by MIME types (e.g. ['image/png']). |
[] |
defaultFolder(string) |
static |
Pre-opens picker modal to a folder slug. | null |
reorderable(bool) |
static |
Enables drag-and-drop reordering. | true |
removable(bool) |
static |
Allows removing selected media. | true |
replaceable(bool) |
static |
Allows swapping selected item. | true |
showFolders(bool) |
static |
Shows folder browser in picker modal. | true |
Placeholder Caching & Performance
When serving APIs or rendering lists with hundreds of media records, looking up extension/kind fallback placeholders continuously can introduce unnecessary CPU overhead.
tsrgtm/media-library features in-memory static placeholder caching:
- Model Memoization:
Media::getPlaceholderUrlAttribute()andMedia::getKindPlaceholderUrlAttribute()cache asset paths per extension and kind combination during request lifecycle execution. - Folder Icon Caching:
MediaFolder::getThumbnailUrlAttribute()caches resolved folder icons statically. - Testing & Cache Clearing: You can clear memoized caches anytime in unit tests or long-running workers:
Resumable TUS Uploads & Queue Processing
Large files (videos, high-res images, archives) are uploaded via chunked TUS HTTP protocols:
- Chunks & Concurrency: 8MB upload chunks with 4 parallel browser connections.
- Auto-Resume: Network drops resume from exact byte offset without restarting.
- Queue Connection: WebP conversion and responsive variants process via queued jobs:
Run worker process in production:
API Controllers & Routes
The package registers administrative and file endpoints under config('media-library.route_prefix') (default /media):
| Route | Name | Description |
|---|---|---|
GET /media/files/{media} |
media.files.show |
Streams media file contents (soft-delete safe). |
GET /media/files/{media}/variant/{variant} |
media.files.variant |
Streams WebP responsive image variant. |
GET /media/picker/browse |
media.picker.browse |
JSON endpoint for Filament MediaPicker modal. |
POST /media/picker/resolve |
media.picker.resolve |
Resolves media details by array of IDs. |
POST /media/tus |
media.tus.create |
Creates TUS resumable upload session. |
PATCH /media/tus/{session} |
media.tus.append |
Appends uploaded chunk data to file session. |
HEAD /media/tus/{session} |
media.tus.offset |
Queries current upload byte offset. |
DELETE /media/tus/{session} |
media.tus.delete |
Cancels and purges upload session. |
Configuration Reference
Package settings located in config/media-library.php:
Testing
Run the Pest test suite:
Or execute directly via Pest:
License
The MIT License (MIT). Please see LICENSE.md for more details.
All versions of media-library with dependencies
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/filesystem Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
filament/filament Version ^5.0
livewire/livewire Version ^4.0
intervention/image Version ^4.2
spatie/laravel-package-tools Version ^1.18