Download the PHP package aniftyco/laravel-attachments without Composer
On this page you can find all versions of the php package aniftyco/laravel-attachments. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aniftyco/laravel-attachments
More information about aniftyco/laravel-attachments
Files in aniftyco/laravel-attachments
Package laravel-attachments
Short Description Turn any field on your Eloquent models into attachments
License MIT
Homepage https://github.com/aniftyco/laravel-attachments
Informations about the package laravel-attachments
Attachments for Laravel
Turn any field on your Eloquent models into attachments with automatic file management and cleanup.
Features
- 🎯 Simple API - Easy-to-use casts for single and multiple attachments
- 🔄 Automatic Cleanup - Automatically delete files when models are deleted
- 🔗 URL Generation - Generate public and temporary URLs for attachments
- 📦 Multiple Storage Disks - Support for any Laravel filesystem disk
- 🗂️ Organized Storage - Automatic folder organization with customizable paths
- 🔒 Type Safe - Full type hints and IDE autocomplete support
Requirements
- PHP 8.3 or higher
- Laravel 12.0 or higher
Installation
You can install the package via Composer:
Publish the configuration file (optional):
Usage
Migrations
Add attachment columns to your migrations using the provided Blueprint macros:
The attachment() and attachments() macros automatically create nullable JSON columns for storing attachment data.
Adding Attachments to Models
To add attachments to your Eloquent models, use the provided cast classes.
Single Attachment
Use the AsAttachment cast to handle a single attachment:
To set an image as an attachment on your model:
Multiple Attachments
Use the AsAttachments cast to handle multiple attachments:
To attach multiple attachments to your model:
Working with Attachments
Accessing Attachment Properties
Generating URLs
File Operations
Working with Multiple Attachments
Automatic File Cleanup
The package provides automatic file cleanup when models are deleted or attachments are replaced.
Model Deletion Cleanup
To enable automatic cleanup when a model is deleted, add the HasAttachmentCleanup trait to your model:
Now when you delete a user, their avatar file will be automatically deleted:
Replacement Cleanup
By default, when you replace an attachment with a new one, the old file is automatically deleted:
Disabling Automatic Cleanup
You can disable automatic cleanup globally in the configuration file:
Configuration
The package comes with sensible defaults, but you can customize the behavior by publishing and editing the configuration file:
Available configuration options:
Testing
Run the test suite:
Run code style checks:
Fix code style issues:
Contributing
Thank you for considering contributing to the Attachments for Laravel package! You can read the contribution guide here.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-attachments with dependencies
illuminate/http Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0