medialibrary-development

Implements file uploads, media collections, and image conversions for Laravel Eloquent models using spatie/laravel-medialibrary.

1|Updated Jun 6, 2026
One-click install
npx skills add https://github.com/karuhun-developer/ecommerce --skill medialibrary-development-karuhun-developer
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: medialibrary-development
Source: https://github.com/karuhun-developer/ecommerce/tree/main/.cursor/skills/medialibrary-development
Command: npx skills add https://github.com/karuhun-developer/ecommerce --skill medialibrary-development-karuhun-developer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires spatie/laravel-medialibrary, and includes references (resource) components.

What problem does it solve? Attaching files to Eloquent models, generating image thumbnails, and managing uploads across storage disks in Laravel requires repetitive boilerplate and careful configuration. This Skill provides the correct patterns for spatie/laravel-medialibrary so media handling works without trial and error. ## Core Features & Use Cases - Model Media Setup: Configure models with HasMedia, InteractsWithMedia, media collections, and conversion definitions. - File Ingestion: Add media from uploads, URLs, strings, base64, streams, or existing disks with custom properties and responsive images. - Retrieval & Delivery: Generate URLs, paths, temporary S3 URLs, srcset markup, and ZIP downloads of collections. - Use Case: When building a product catalog where each product needs a single avatar, a gallery collection limited to five images, and queued thumbnail conversions stored on S3, this Skill supplies the exact collection, conversion, and retrieval code. ## Quick Start Add a single-file avatar collection and a 300x300 thumbnail conversion to my Laravel Product model using spatie/laravel-medialibrary.

Frequently Asked Questions about medialibrary-development

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I attach files to an Eloquent model in Laravel?▼

Implement the HasMedia interface and use the InteractsWithMedia trait on the model, then call addMedia with the file followed by toMediaCollection. Files can also be added from URLs, requests, base64 strings, streams, or existing disks.

How do I generate image thumbnails with spatie/laravel-medialibrary?▼

Define conversions inside registerMediaConversions using addMediaConversion with a fit method such as Fit::Contain and target dimensions. Use nonQueued for synchronous generation or queued for background processing, then retrieve them via getFirstMediaUrl with the conversion name.

Does spatie/laravel-medialibrary support S3 storage?▼

Yes, collections can specify a disk with useDisk, and conversions can be stored separately with storeConversionsOnDisk. Temporary URLs for private S3 files are available through getFirstTemporaryUrl with an expiration time.

Why is my uploaded media not being saved in Laravel medialibrary?▼

The most common cause is calling addMedia without finalizing with toMediaCollection, which is required to persist the file. Also verify the medialibrary migration was published and run before adding media.

How do I limit a media collection to a single file?▼

Call singleFile on the collection definition inside registerMediaCollections. Uploading a new file then automatically replaces the previous one, and you can pair it with useFallbackUrl for a default image when the collection is empty.