Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Attachment Library Laravel Package

van-ons/laravel-attachment-library

Attach files to Laravel Eloquent models with a simple HasAttachments trait and Attachment model. Includes installer command for migrations/assets and an attachments relationship to link existing uploads to any model.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature Development:

    • File Management for Eloquent Models: Accelerates development of features requiring file attachments (e.g., user avatars, document uploads, e-commerce product images). Reduces boilerplate by providing a standardized way to handle attachments via the HasAttachments trait.
    • Customizable File Handling: Enables tailored solutions for niche use cases (e.g., metadata extraction, filename sanitization, or directory structures) through extensible components like FileNamer, MetadataAdapter, and Attachment model extensions.
    • Responsive Images: Supports performance-critical features like adaptive image loading (via Glide integration) for responsive design, reducing page load times and improving UX.
  • Roadmap Prioritization:

    • Build vs. Buy: Justifies adopting this package over custom development for core file-management needs, freeing engineering bandwidth for higher-value initiatives. Ideal for teams lacking dedicated backend resources for file systems.
    • Scalability: Aligns with roadmap items requiring robust file storage (e.g., document management systems, media-heavy platforms). The package’s disk-agnostic design (supports S3, local storage, etc.) future-proves infrastructure choices.
    • Integration with Frontend Frameworks: Complements roadmap items involving Filament or Livewire by leveraging the Filament Attachment Library for seamless admin panel integrations.
  • Use Cases:

    • Content Management Systems (CMS): Attach files to articles, blog posts, or media libraries with minimal effort.
    • E-Commerce: Manage product images, invoices, or customer uploads (e.g., warranty documents) tied to orders or users.
    • Document Workflows: Build systems for invoices, contracts, or educational materials with versioning and metadata (e.g., file size, dimensions).
    • User-Generated Content: Enable profile pictures, portfolio uploads, or community-driven file sharing (e.g., forums, social platforms).

When to Consider This Package

  • Adopt This Package If:

    • Your Laravel application requires file attachments linked to Eloquent models (e.g., users, products, posts) with minimal custom code.
    • You need customizable file handling (e.g., metadata extraction, filename sanitization, or directory structures) without reinventing the wheel.
    • Your team lacks dedicated backend resources to build a scalable file management system from scratch.
    • You’re using Filament or Livewire and want a seamless way to manage attachments in admin panels.
    • Your use case involves responsive images (e.g., e-commerce, media sites) and you want to leverage Glide for on-the-fly optimization.
    • You prioritize developer efficiency and want to avoid repetitive CRUD logic for file uploads/deletes.
  • Look Elsewhere If:

    • You need advanced features like collaborative editing, version control, or complex access controls (consider packages like Spatie Media Library or Intervention Image).
    • Your application requires video/audio processing beyond basic metadata (e.g., FFmpeg integration).
    • You’re building a highly specialized file system (e.g., CAD files, 3D models) with unique validation rules.
    • Your team has dedicated backend resources to build a custom solution tailored to edge cases.
    • You need real-time file previews or heavy client-side processing (consider frontend libraries like Dropzone.js or TUS for uploads).

How to Pitch It (Stakeholders)

For Executives:

"This package lets us rapidly add file management to our Laravel app—think user uploads, product images, or documents—without building a custom system from scratch. It’s like adding a ‘file cabinet’ to our models (e.g., users, orders) with just a few lines of code. For example, an e-commerce feature for customer invoices could be implemented in hours instead of weeks. It also integrates with our Filament admin panel, reducing frontend-backend handoff time. The cost? Minimal—just a Composer install and a migration. The ROI? Faster feature delivery, lower dev overhead, and scalability for future media-heavy features."

For Engineering Teams:

*"This library solves a common pain point: attaching files to Eloquent models cleanly and efficiently. Key benefits:

  • Traits over ORM: Add HasAttachments to any model to enable file uploads/deletes with zero boilerplate.
  • Extensible: Need custom filename rules or metadata? Extend the FileNamer or MetadataAdapter classes. Example: Sanitize filenames or extract EXIF data without reinventing the wheel.
  • Glide Integration: Serve optimized, responsive images on-the-fly (e.g., product thumbnails) without bloating storage.
  • Filament Ready: Works seamlessly with Filament Attachment Library for admin panels.
  • Lightweight: MIT-licensed, actively maintained, and designed for performance (e.g., Glide caching).

Trade-offs:

  • Not a full-fledged DAM (Digital Asset Management) system—avoid if you need advanced features like AI tagging or collaborative editing.
  • Requires basic Laravel setup (e.g., storage disks, migrations).

Proposal: Use this for core file-management needs (e.g., user avatars, product images) and pair it with Spatie Media Library for edge cases. This combo covers 90% of use cases while keeping the codebase maintainable."*

For Developers:

*"Here’s how this package saves you time:

  1. Attach Files to Models in 2 Steps:

    use VanOns\LaravelAttachmentLibrary\Concerns\HasAttachments;
    class User extends Model { use HasAttachments; }
    

    Now User::find(1)->attachments works out of the box.

  2. Upload/Manage Files Programmatically:

    // Upload
    $attachment = AttachmentManager::upload($request->file('document'));
    
    // Resize images
    $resized = Resizer::src($attachment)->width(300)->resize();
    
    // Blade component for responsive images
    <x-laravel-attachment-library-image :src="$image" />
    
  3. Customize Without Forking:

    • Override Attachment model behavior (e.g., add is_public field).
    • Extend FileNamer to enforce your naming conventions (e.g., slugify()).
    • Swap metadata providers (e.g., add PDF metadata extraction).
  4. Glide for Image Optimization:

    • Automatic caching of resized images (configurable in glide.php).
    • CDN-friendly URLs with signatures for security.

When to Avoid:

  • If you need client-side processing (e.g., real-time previews), pair this with a frontend library like Dropzone.js.
  • If you’re building a video/audio platform, consider FFmpeg integrations.

Getting Started:

composer require van-ons/laravel-attachment-library
php artisan attachment-library:install

Then add the trait to your models and start attaching files!"*

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor