PHPackages                             teamteatime/laravel-filer - 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. teamteatime/laravel-filer

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

teamteatime/laravel-filer
=========================

A simple Laravel ORM file attachment solution supporting multiple relationship types

1.0.2(9y ago)272.6k4[2 issues](https://github.com/Team-Tea-Time/laravel-filer/issues)MITPHPPHP &gt;=5.4.0

Since May 24Pushed 8y ago2 watchersCompare

[ Source](https://github.com/Team-Tea-Time/laravel-filer)[ Packagist](https://packagist.org/packages/teamteatime/laravel-filer)[ RSS](/packages/teamteatime-laravel-filer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Please be aware that this package **is not** designed to handle uploading or image manipulation. It's simply designed to compliment other packages and tools that already exist in Laravel. If you're looking for a more feature-complete attachments solution, take a look at [CodeSleeve/stapler](https://github.com/CodeSleeve/stapler).

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

[](#installation)

### Step 1: Install the package

[](#step-1-install-the-package)

Install the package via Composer:

```
composer require teamteatime/laravel-filer

```

Add the service provider to your `config/app.php`:

```
TeamTeaTime\Filer\FilerServiceProvider::class,
```

> If your app defines a catch-all route, make sure you load this service provider before your app service providers.

### Step 2: Publish the package files

[](#step-2-publish-the-package-files)

Run the vendor:publish command to publish Filer's migrations:

`php artisan vendor:publish`

### Step 3: Update your database

[](#step-3-update-your-database)

Run your migrations:

`php artisan migrate`

### Step 4: Update your models

[](#step-4-update-your-models)

Add attachment support to your models by using the HasAttachments trait:

```
class ... extends Eloquent {
    use \TeamTeaTime\Filer\HasAttachments;
}
```

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

[](#configuration)

Filer requires no configuration out of the box in most cases, but the following options are available to you in `config/filer.php`:

OptionTypeDescriptionDefaultroutesBooleanDetermines whether or not to automatically define filer's routes. If you set this to `false`, you can optionally use `\TeamTeaTime\Filer\Filer::routes($router, $namespace)` in your routes.php.trueroute\_prefixstringIf routes are enabled, this is used for all route prefixes.fileshash\_routesBooleanEnables unique hashes for local files to obfuscate their IDs in routes.falsehash\_lengthstringThe length to use when generating hashes for local files.40pathArrayContains the relative and absolute paths to the directory where your attachment files are stored.storage\_path('uploads')append\_querystringBooleanIf enabled, attachment URLs include a querystring containing the attachment's updated\_at timestamp. This prevents out of date attachments from being loaded by the browser.truecleanup\_on\_deleteBooleanIf enabled, Filer will attempt to delete local files referenced by deleted attachments.trueUsage
-----

[](#usage)

To attach a file or URL, use the `attach()` method on your model. This method will accept any of the following:

...a **local file path**

```
$user->attach('avatars/1.jpg'); // path relative to your configured storage directory
```

...an instance of **SplFileInfo**

```
$photo = Request::file('photo')->move($destinationPath);
$user->attach($photo);
```

> `Symfony\Component\HttpFoundation\File\File`, `Symfony\Component\HttpFoundation\File\UploadedFile` and `Illuminate\Http\UploadedFile` are extensions of `SplFileInfo` and Laravel Requests contain the latter by default.

...or a **URL**

```
$user->attach('http://www.analysis.im/uploads/seminar/pdf-sample.pdf');
```

You can also specify a key (which uniquely identifies the attachment), a title, and/or a description using the options array:

```
$user->attach('uploads/avatars/1.jpg', ['key' => 'avatar']);
```

```
$article->attach($pdf, ['title' => "Event 2015 Guide", 'description' => "The complete guide for this year's event."]);
```

By default, attachments are associated with user IDs using `Auth::id()`. You can override this at call time:

```
$user->attach($photo, ['user_id' => $user->id]);
```

```
$article->attach($pdf, ['user_id' => null]);
```

Depending on what you pass to this method, the item will be stored as either a `TeamTeaTime\Filer\LocalFile` or a `TeamTeaTime\Filer\Url`. You can later call on attachments via the `attachments` relationship. Examples are provided below.

### Displaying a list of attachments in a view

[](#displaying-a-list-of-attachments-in-a-view)

```
@foreach ($article->attachments as $attachment)
{{ $attachment->title }}
{{ $attachment->description }}
@endforeach

```

### Retrieving an attachment by ID or key

[](#retrieving-an-attachment-by-id-or-key)

```
$user->attachments()->find($attachmentId);
```

```
$user->findAttachmentByKey('avatar');
```

### Accessing an attachment's properties and type-specific properties

[](#accessing-an-attachments-properties-and-type-specific-properties)

```
$avatar = $user->findAttachmentByKey('avatar');
$avatar->getUrl();          // the URL to the file (see below)
$avatar->getDownloadUrl();  // the download URL to the file (see below)
$avatar->title;             // the attachment title, if any
$avatar->description;       // the attachment description, if any

// If the attachment is a LocalFile...
$avatar->item->filename;    // the filename, with its extension
$avatar->item->path;        // the path to the directory where the file exists
$avatar->item->mimetype;    // the file's detected MIME type
$avatar->item->size;        // the file size, in bytes
$avatar->item->getFile();   // the Symfony File representation of the file
$avatar->item->hash;        // the unique hash generated for the file (if filer.hash_routes is enabled)
```

### Generating URLs

[](#generating-urls)

The `getUrl()` and `getDownloadUrl()` methods above will return different values based on the attachment type; if it's a local file, they will return the 'view' and 'download' routes respectively, otherwise they'll return the URL that was attached.

For local files, the provided routes can be generated with a file ID or hash:

```
route('filer.file.view', $fileId);
```

```
route('filer.file.download', $fileId)
```

> Note that depending on the file's MIME type, the browser may begin a download with both of these routes.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

3

Last Release

3638d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2597f35fc9c6ae22401a9e6ab8794283b43a4fb951c073f704c0909d95ca5bd2?d=identicon)[Riari](/maintainers/Riari)

---

Top Contributors

[![albertcat](https://avatars.githubusercontent.com/u/1935397?v=4)](https://github.com/albertcat "albertcat (1 commits)")[![madbob](https://avatars.githubusercontent.com/u/166089?v=4)](https://github.com/madbob "madbob (1 commits)")[![Riari](https://avatars.githubusercontent.com/u/3583774?v=4)](https://github.com/Riari "Riari (1 commits)")[![victorlap](https://avatars.githubusercontent.com/u/1645632?v=4)](https://github.com/victorlap "victorlap (1 commits)")

---

Tags

laravelfileslaravel 5attachments

### Embed Badge

![Health badge](/badges/teamteatime-laravel-filer/health.svg)

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

###  Alternatives

[gaspertrix/laravel-backpack-dropzone-field

Add Dropzone support for Laravel Backpack

172.2k](/packages/gaspertrix-laravel-backpack-dropzone-field)

PHPackages © 2026

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