Laravel Media Library

Associate files and media with Eloquent models in Laravel applications.

Library
Composer
v11.23.5
6,158stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
86/100Excellent
Development Activity80
Maintenance84
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
85/100Excellent
Architecture88
Code Quality90
Innovation86
Learning Curve74

spatie/laravel-medialibrary is a mature Laravel package for associating files with Eloquent models. Any model can be made an owner of media, gaining the ability to attach uploaded files, remote URLs, or streams, organize them into named collections, and store them across any Flysystem disk (local, S3, and more).

Beyond storage, the package automatically generates image conversions and responsive images, integrates with queued jobs for heavy processing, and provides a clean API for retrieving media URLs, paths, and custom properties, making it a comprehensive solution for handling user uploads and media assets.

What You Get

  • A HasMedia contract and InteractsWithMedia trait for Eloquent models
  • Named media collections with per-collection rules
  • Automatic image conversions and responsive image generation
  • Storage on any Flysystem disk, including S3
  • Queueable processing for conversions and heavy work
  • APIs for URLs, paths, custom properties, and ordering

Common Use Cases

  • Handling user avatar and profile image uploads
  • Managing image galleries attached to products or posts
  • Generating thumbnails and responsive image variants
  • Storing document attachments on cloud disks

Under The Hood

Architecture - A model opts in via the HasMedia interface and InteractsWithMedia trait, which expose a fluent addMedia() file-adder pipeline (in src/MediaCollections) that validates, names, and persists files as Media records linked polymorphically to the owner. Image derivatives are produced by the Conversions subsystem (leveraging spatie/image and optimizers), responsive variants by ResponsiveImages, and remote sources by Downloaders. The MediaLibraryServiceProvider wires configuration, migrations, and commands. Tech Stack - PHP built on Laravel (Eloquent, the filesystem/Flysystem abstraction, queues) plus spatie/image for manipulation; distributed under MIT and actively maintained on an 11.x line. Code Quality - This is a flagship Spatie package with an extensive Pest/PHPUnit test suite, continuous integration, thorough documentation, and a very high level of activity (2600+ commits, 100 releases, 400+ contributors). API Design - The developer experience is a major strength: expressive chained calls like $model->addMedia($file)->toMediaCollection('images') and $model->getFirstMediaUrl('images', 'thumb') keep common tasks concise, and collection/conversion registration is declarative inside the model.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search