medialibrary-development

Automate attaching and managing media files to Eloquent models with Laravel Medialibrary.

1.5k|170|Updated Sep 25, 2024
One-click install
npx skills add https://github.com/relaticle/relaticle --skill medialibrary-development-relaticle
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: medialibrary-development
Source: https://github.com/relaticle/relaticle/tree/main/.claude/skills/medialibrary-development
Command: npx skills add https://github.com/relaticle/relaticle --skill medialibrary-development-relaticle

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Attach and manage media on Eloquent models in Laravel using Spatie's medialibrary, solving the challenge of organizing, transforming, and delivering media assets.

Core Features & Use Cases

  • Associate files with Eloquent models using HasMedia and InteractsWithMedia
  • Define media collections, conversions, and responsive images
  • Retrieve media URLs/paths for display, downloads, and previews
  • Use cases include image attachments, document handling, and media-driven features in CRUD apps

Quick Start

Attach a local image to a BlogPost by calling addMedia($file)->toMediaCollection('images') after ensuring the model implements HasMedia.

Frequently Asked Questions about medialibrary-development

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

FAQPage Schema
How do I attach and manage media files to Eloquent models in Laravel?

To attach media files to Eloquent models in Laravel, implement the HasMedia and InteractsWithMedia interfaces, then call addMedia($file)->toMediaCollection('images') on your model to store and link the file.

What are media collections and conversions in Laravel media management?

Media collections organize attached files by group, while conversions define automated image transformations like resizing. You define both inside your model's registerMediaCollections and registerMediaConversions methods to control file handling and rendering.

How do I retrieve media URLs from an Eloquent model for display?

To retrieve media URLs from an Eloquent model, use the getMedia() method to fetch all files in a collection or getFirstMediaUrl() to get the direct URL of the first attached file for frontend display or downloads.

Can I generate responsive images for attached files in Laravel?

Yes, you can generate responsive images for attached files in Laravel by defining them within your registerMediaConversions method. This allows the medialibrary to automatically generate and serve appropriately sized images for different screen dimensions.

What's the best way to handle image attachments and document files in Laravel CRUD apps?

The best way to handle image attachments and documents in Laravel CRUD apps is using a dedicated media management package, allowing you to associate files directly with Eloquent models, define custom conversions, and retrieve media URLs seamlessly.