PHPackages                             phunky/laravel-messaging-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phunky/laravel-messaging-attachments

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phunky/laravel-messaging-attachments
====================================

Message attachments extension for phunky/laravel-messaging

0.1.1(2mo ago)00MITPHP ^8.4

Since Apr 16Compare

[ Source](https://github.com/Phunky/laravel-messaging-attachments)[ Packagist](https://packagist.org/packages/phunky/laravel-messaging-attachments)[ Docs](https://github.com/phunky/laravel-messaging-attachments)[ RSS](/packages/phunky-laravel-messaging-attachments/feed)WikiDiscussions Synced 3w ago

READMEChangelog (3)Dependencies (12)Versions (6)Used By (0)

Laravel Messaging Attachments
=============================

[](#laravel-messaging-attachments)

Attach files and media to messages in [phunky/laravel-messaging](https://github.com/phunky/laravel-messaging) conversations. This extension stores attachment metadata (path, disk, MIME type, size, and arbitrary JSON) alongside each message, while leaving actual file storage entirely to your application.

Requirements
------------

[](#requirements)

- PHP ^8.4
- `[phunky/laravel-messaging](https://packagist.org/packages/phunky/laravel-messaging)` ^0.0.1

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

[](#installation)

```
composer require phunky/laravel-messaging-attachments
```

Register the extension in `config/messaging.php`:

```
'extensions' => [
    \Phunky\LaravelMessagingAttachments\AttachmentExtension::class,
],
```

Run migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

Inject `AttachmentService` — or resolve it from the container — wherever you handle uploads.

```
use Phunky\LaravelMessagingAttachments\AttachmentService;

class MessageController extends Controller
{
    public function __construct(private AttachmentService $attachments) {}

    public function store(Request $request, Message $message)
    {
        $path = $request->file('file')->store('attachments', 'public');

        $attachment = $this->attachments->attach($message, $request->user(), [
            'type'      => 'image',
            'path'      => $path,
            'filename'  => $request->file('file')->getClientOriginalName(),
            'disk'      => 'public',
            'mime_type' => $request->file('file')->getMimeType(),
            'size'      => $request->file('file')->getSize(),
        ]);
    }
}
```

### Attaching files

[](#attaching-files)

```
// Single attachment — returns Attachment model
$attachment = $attachmentService->attach($message, $sender, [
    'type'      => 'image',          // required — e.g. 'image', 'video', 'document', 'audio'
    'path'      => 'uploads/a.jpg',  // required — path on the disk
    'filename'  => 'photo.jpg',      // required — original file name
    'disk'      => 'public',         // optional — Laravel filesystem disk
    'url'       => 'https://...',    // optional — direct or CDN URL
    'mime_type' => 'image/jpeg',     // optional
    'size'      => 204800,           // optional — size in bytes
    'order'     => 0,                // optional — position; auto-increments when omitted
    'meta'      => ['width' => 800], // optional — arbitrary JSON data
]);

// Multiple attachments in one transaction — returns Collection
$attachments = $attachmentService->attachMany($message, $sender, [
    ['type' => 'image', 'path' => 'a.jpg', 'filename' => 'a.jpg'],
    ['type' => 'image', 'path' => 'b.jpg', 'filename' => 'b.jpg'],
]);
```

Only the original message sender can attach or detach files. Attempts by anyone else throw `Phunky\LaravelMessaging\Exceptions\CannotMessageException`.

### Removing an attachment

[](#removing-an-attachment)

```
// Deletes the record and dispatches AttachmentDetached
$attachmentService->detach($message, $sender, $attachment);
```

### Fetching attachments

[](#fetching-attachments)

```
// All attachments for a message, ordered by position then id
$attachments = $attachmentService->getAttachments($message);

// All attachments across a whole conversation,
// ordered by message sent_at (newest first), then attachment order and id
$attachments = $attachmentService->getAttachmentsForConversation($conversation);
```

### Relationship macro

[](#relationship-macro)

`Message::attachments()` is registered as a `hasMany` macro — call it as a method, not a property:

```
$message->refresh();
$message->attachments()->get();   // returns all Attachment models
$message->attachments()->count();
```

Events
------

[](#events)

Both events use `Dispatchable` and `SerializesModels` and are safe to queue.

EventProperties`AttachmentAttached``Attachment $attachment`, `Message $message`, `Messageable $messageable``AttachmentDetached``Message $message`, `Messageable $messageable`, `int```
use Phunky\LaravelMessagingAttachments\Events\AttachmentAttached;

Event::listen(AttachmentAttached::class, function (AttachmentAttached $event) {
    // Generate a thumbnail, push a notification, etc.
    GenerateThumbnail::dispatch($event->attachment->path, $event->attachment->disk);
});
```

`AttachmentDetached` carries the `$attachmentId` rather than a model because the record has already been deleted by the time the event fires.

Storage
-------

[](#storage)

This extension is **storage-agnostic** — it records where a file lives, not the file itself. Upload the file through Laravel's filesystem first, then pass the resulting path and disk to `attach()`. This works with any driver: `local`, `public`, `s3`, or any custom disk.

```
// Local disk
$path = $request->file('avatar')->store('avatars', 'local');

// S3
$path = $request->file('document')->store('documents', 's3');

// Then record the attachment
$attachmentService->attach($message, $user, [
    'type'     => 'document',
    'path'     => $path,
    'filename' => $request->file('document')->getClientOriginalName(),
    'disk'     => 's3',
]);
```

Deleting the underlying file from storage when an attachment is detached is your application's responsibility — listen to `AttachmentDetached` and remove the file using `Storage::disk($disk)->delete($path)`.

License
-------

[](#license)

MIT - see [LICENSE.md](LICENSE.md).

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance83

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

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 ~7 days

Total

3

Last Release

84d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/67351?v=4)[Mark Harwood](/maintainers/Phunky)[@Phunky](https://github.com/Phunky)

---

Top Contributors

[![Phunky](https://avatars.githubusercontent.com/u/67351?v=4)](https://github.com/Phunky "Phunky (8 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

---

Tags

laravelchatattachmentslaravel-messaging

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[musonza/chat

Chat Package for Laravel

1.2k276.7k1](/packages/musonza-chat)[lexxyungcarter/chatmessenger

Simple one-to-one/group chat messaging tool for Laravel 5, 6, 7, 8, 9 &amp; 10 with Pusher Integration

10725.7k](/packages/lexxyungcarter-chatmessenger)

PHPackages © 2026

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