New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

digit-soft/laravel-attachments

File attachments for laravel.
3,891
Install
composer require digit-soft/laravel-attachments
Latest Version:1.3.9
PHP:^8.1
Laravel:10 – 13
Older releases:5 – 9
License:MIT
Last Updated:Apr 9, 2026
Links: GitHub  ·  Packagist
Maintainer: digitv

Attach files to Eloquent models

This package gives you models, traits and some examples for attaching files to any Eloquent model and write down those usages. Also provides use of private files (downloaded through framework with user token).

Possible flow:

  1. You upload a file
  2. Create Attachment model for this file
  3. Write down usage of this attachment by your model

If you delete this model, usage will be deleted. If you reSave your model with another attachment - usage will be deleted.

Unused attachments can be deleted by running cleanup (@see Facades/Attachments).

Uploaded images can be automatically resized to max size given in config, there is a job for that.

See AttachmentManager for further usage.

Made for Rest API projects. Ideally must be controller for file upload and another one for download (private files). Controller examples are in src/Controllers directory.

There is also image processing controller example, which uses hexadecimal encoded width/height data, it is resizing images on the fly and puts resized images to the cache folder. You can use NGINX, for example, to download cached image next time.

Traits

You can found usable model traits in src/Traits directory. They use an observer for save/delete events.

  • HasAttachments - General trait for use withing model
  • HasAttachmentById - trait for model with single attachment_id field

Console

Create migration

You can create DB migration for Attachment models by running artisan command:

php artisan attachments:tables
Create directories fo files

Command will create directories for attachments save/publishing.

php artisan attachments:directories

Related Packages

oi-lab/oi-laravel-attachments

Polymorphic file attachments, files and folders for Laravel applications

1,907 0
dcodegroup/laravel-attachments

Allow adding attachments to any document

33,057 1
aniftyco/laravel-attachments

Turn any field on your Eloquent models into attachments

1,126 13
oval/laravel-upload-helper

Upload helper library for Laravel

550 3
empari/files

Management Files for Laravel

11 0

Version History

Version Released PHP Laravel License
1.3.9 ^8.1 >=10.48.29 <11.0.0|^11.0|^12.0|^13.0 MIT
1.3.8 ^8.1 ^8.40|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
1.3.7 ^8.1 ^8.40|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
1.3.6 ^8.1 ^8.40|^9.0|^10.0|^11.0|^12.0 MIT
1.3.5 ^8.1 ^8.40|^9.0|^10.0|^11.0|^12.0 MIT