PHPackages                             codeitamarjr/laravel-attachments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. codeitamarjr/laravel-attachments

ActiveLibrary[File &amp; Storage](/categories/file-storage)

codeitamarjr/laravel-attachments
================================

Persist and manage polymorphic file attachments in Laravel applications.

v0.6.0(1mo ago)216MITPHPPHP ^8.3

Since Oct 28Pushed 6mo agoCompare

[ Source](https://github.com/codeitamarjr/laravel-attachments)[ Packagist](https://packagist.org/packages/codeitamarjr/laravel-attachments)[ Docs](https://github.com/codeitamarjr/Laravel-Attachments)[ RSS](/packages/codeitamarjr-laravel-attachments/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (7)Used By (0)

Laravel Attachments
===================

[](#laravel-attachments)

Reusable polymorphic attachment handling for Laravel 11/12 projects.
Provides a trait, service, migration stub, and configuration for storing files on any configured filesystem (including Cloudflare R2).

Repository:

Installation
------------

[](#installation)

1. **Require the package** (when using it as a standalone dependency):

    ```
    composer require codeitamarjr/laravel-attachments
    ```

    When using locally (e.g. inside QuickTapPay) you can also reference it with a path repository entry.
2. **Publish assets (optional)**

    ```
    php artisan vendor:publish --tag=attachments-config
    php artisan vendor:publish --tag=attachments-migrations
    ```

    The config file allows you to set the target filesystem disk and base directory. The migration stub creates the `attachments` table.
3. **Run migrations**

    ```
    php artisan migrate
    ```

Usage
-----

[](#usage)

### Model Trait

[](#model-trait)

Use the `HasAttachments` trait on any Eloquent model that needs attachments:

```
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use CodeItamarJr\Attachments\Traits\HasAttachments;

class User extends Model
{
    use HasAttachments;

    protected $appends = ['avatar_url'];

    public function avatarAttachment(): MorphOne
    {
        return $this->attachment('avatar');
    }

    public function getAvatarUrlAttribute(): ?string
    {
        return $this->avatarAttachment()->first()?->url();
    }
}
```

This adds the `attachments()` morph-many relation plus a helper `attachment($collection)` and `attachmentUrl($collection)`.

### Attachment Service

[](#attachment-service)

Inject the `AttachmentService` to store, replace, or delete attachments:

```
use CodeItamarJr\Attachments\Services\AttachmentService;

class ProfileController extends Controller
{
    public function update(AttachmentService $attachments)
    {
        $user = request()->user();
        $file = request()->file('avatar');

        if ($file) {
            $attachments->replace($user, $file, 'avatar', $user->getKey());
        }
    }
}
```

### Collections

[](#collections)

Attachments can be grouped by collection name (default `default`). For example, use `attachment('avatar')` or `attachmentUrl('avatar')` to reference a user's profile photo.

### Deleting

[](#deleting)

When a model using `HasAttachments` is force-deleted, associated attachments are automatically removed from both storage and the database.
You can also delete explicitly:

```
app(AttachmentService::class)->delete($user, 'avatar');
```

Configuration
-------------

[](#configuration)

`config/attachments.php` exposes:

- `disk` – filesystem disk, defaults to `ATTACHMENTS_DISK` env or `FILESYSTEM_DISK`.
- `directory` – base directory on the disk (`attachments` by default).

Testing
-------

[](#testing)

The package is compatible with `orchestra/testbench` for isolated package testing.
To run tests (if added later):

```
cd laravel-attachments
composer install
./vendor/bin/pest
```

License
-------

[](#license)

MIT © 2025 Itamar Junior

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance78

Regular maintenance activity

Popularity9

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~39 days

Total

6

Last Release

39d ago

PHP version history (2 changes)v0.1.0PHP ^8.2

v0.4.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dea1e9b29f49d63c69e129ab9e08825fd7155c2db0f91824dfd5f165c278b979?d=identicon)[codeitamarjr](/maintainers/codeitamarjr)

---

Tags

filesystemlaravelfilesattachmentsuploads

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codeitamarjr-laravel-attachments/health.svg)

```
[![Health](https://phpackages.com/badges/codeitamarjr-laravel-attachments/health.svg)](https://phpackages.com/packages/codeitamarjr-laravel-attachments)
```

###  Alternatives

[spatie/laravel-google-cloud-storage

Google Cloud Storage filesystem driver for Laravel

2408.9M13](/packages/spatie-laravel-google-cloud-storage)[zing/laravel-flysystem-obs

Flysystem Adapter for OBS

1211.2k](/packages/zing-laravel-flysystem-obs)[sausin/laravel-ovh

OVH Object Storage driver for laravel

40153.5k](/packages/sausin-laravel-ovh)[andrewelkins/cabinet

Laravel 4 file upload package.

1011.5k](/packages/andrewelkins-cabinet)[yoelpc4/laravel-cloudinary

Laravel Cloudinary filesystem cloud driver.

3343.0k](/packages/yoelpc4-laravel-cloudinary)[torann/mediasort

Attachment manager for Laravel.

2012.5k](/packages/torann-mediasort)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
