PHPackages                             inakianduaga/eloquent-external-storage - 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. [Database &amp; ORM](/categories/database)
4. /
5. inakianduaga/eloquent-external-storage

ActiveLibrary[Database &amp; ORM](/categories/database)

inakianduaga/eloquent-external-storage
======================================

Adds transparent external storage to an eloquent model

v1.0(11y ago)31152[3 issues](https://github.com/inakianduaga/eloquent-external-storage/issues)MITPHPPHP &gt;=5.5.0

Since Jan 11Pushed 10y agoCompare

[ Source](https://github.com/inakianduaga/eloquent-external-storage)[ Packagist](https://packagist.org/packages/inakianduaga/eloquent-external-storage)[ RSS](/packages/inakianduaga-eloquent-external-storage/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (11)Used By (0)

eloquent-external-storage
=========================

[](#eloquent-external-storage)

[![Build Status](https://camo.githubusercontent.com/b1413de2d670eac1967855f8811b78a3aa7e3759722d749fe0d38da62e3c4086/68747470733a2f2f7472617669732d63692e6f72672f696e616b69616e64756167612f656c6f7175656e742d65787465726e616c2d73746f726167652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/inakianduaga/eloquent-external-storage) [![Coverage Status](https://camo.githubusercontent.com/ae327950f406498da8281a563a1318f8bc0cb4afde6a443d098c63a632d88faa/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f696e616b69616e64756167612f656c6f7175656e742d65787465726e616c2d73746f726167652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/inakianduaga/eloquent-external-storage) [![Code Climate](https://camo.githubusercontent.com/201cbe460410193c7a16159dc675c019a20a42691daeec888d920870d4f2bc36/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f696e616b69616e64756167612f656c6f7175656e742d65787465726e616c2d73746f726167652f6261646765732f6770612e737667)](https://codeclimate.com/github/inakianduaga/eloquent-external-storage) [![HHVM Status](https://camo.githubusercontent.com/dc0464297f3c1a89746ae7ee4ef2fc28bf33d1d77128fb36396c20f375abe06f/687474703a2f2f6868766d2e683463632e64652f62616467652f696e616b69616e64756167612f656c6f7175656e742d65787465726e616c2d73746f726167652e737667)](http://hhvm.h4cc.de/package/inakianduaga/eloquent-external-storage) [![Dependency Status](https://camo.githubusercontent.com/07b58466e97a8a688499a9b53696a6867c75e792cf98b6020976608faf34ea8b/68747470733a2f2f67656d6e617369756d2e636f6d2f696e616b69616e64756167612f656c6f7175656e742d65787465726e616c2d73746f726167652e737667)](https://gemnasium.com/inakianduaga/eloquent-external-storage)

> Adds external storage capabilities to an eloquent model.

Features
--------

[](#features)

- Save/retrieve model-related content to an external storage using `setContent()`, `getContent()` methods on the eloquent model. Now you can move all that binary data out of the database without having to move a finger.
- Storage supports different drivers, currently `file` and `Amazon AWS S3` are implemented
- Different models can implement different storage drivers, separate configurations
- Storage drivers can be updated on the fly.

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

[](#installation)

### Add package as a composer dependency

[](#add-package-as-a-composer-dependency)

In your `composer.json` file, include

```
"require": {
        "inakianduaga/eloquent-external-storage" : "dev-master",
    },
```

and then run

`composer update --no-scripts inakianduaga/laravel-html-builder-extensions`

to install the package

### Database configuration

[](#database-configuration)

The storage driver needs three additional fields, where it stores the content path, an md5 checksum of the contents, and the driver class used to store the contents.

- A migration example is provided under `src/migration`.
- The database field names can be custom-named, simply modify the model's $databaseFields property

```
class ActualModel extends InakiAnduaga\EloquentExternalStorage\Models\AbstractModelWithExternalStorage {

    /**
     * Under what db field we store the content path/md5/storage_driver_class for this model
     */
    protected $databaseFields = array(
        'contentPath' => 'content_path',
        'contentMD5' => 'content_md5',
        'storage_driver' => 'storage_driver',
    );

}
```

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

[](#configuration)

Each model (class) that needs external storage must have a configuration set, controlled by model properties:

```
class ActualModel extends InakiAnduaga\EloquentExternalStorage\Models\AbstractModelWithExternalStorage {

   /**
    * This is the path to the driver configuration that will be used for this model class, independently of other classes
    */
   protected static $storageDriverConfigPath;
}
```

### Choosing / changing a storage driver dynamically

[](#choosing--changing-a-storage-driver-dynamically)

If you want to switch storage drivers dynamically for a given model, you can do so by using the model's `setStorageDriver(StorageDriver $driver, $storageDriverConfigurationPath = null)` method. This will use the given driver with the chosen configuration path (or leave the current config path if `null`)

### Drivers configuration

[](#drivers-configuration)

The package provides placeholder configurations for the different included drivers. In the laravel installation root folder, run

`php artisan config:publish inakianduaga/eloquent-external-storage`

You can then modify the placeholder values in the files

- Aws S3 driver: `app/config/packages/inakianduaga/eloquent-external-storage/awsS3.php`
- File driver `app/config/packages/inakianduaga/eloquent-external-storage/file.php`

Note that you should set the models `$storageDriverConfigPath` property to point to `inakianduaga/eloquent-external-storage::awsS3` for the example above, when using S3.

Usage:
------

[](#usage)

- Simply extend `InakiAnduaga\EloquentExternalStorage\Models\AbstractModelWithExternalStorage` in your eloquent model (or use the trait `InakiAnduaga\EloquentExternalStorage\Models\ModelWithExternalStorageTrait` if you can't use class extension.

    - In the extended model, set driver/database config properties (see above).
- To attach/retrieve external content associated to a model

    - Use `setContent` method on the model to set the content (will be actually saved on update/save/creation)
    - Use `getContent` to retrieve the actual contents

Development &amp; Testing
-------------------------

[](#development--testing)

### Requirements

[](#requirements)

- Install `node` &amp; `npm`, afterwards run `npm install` to install development tools
- Install `sqlite` driver for running tests

    - **Ubuntu**: `sudo apt-get install sqlite3 libsqlite3-dev` and afterwards `sudo apt-get install php5-sqlite`

### Tools

[](#tools)

There are several commands related to testing

- `gulp test` : runs unit tests once
- `gulp tdd` : runs unit tests continuously once changes are detected

Both options have the ability to generate a code coverage report in different formats. When this is selected, a local server will be launched to visualize the coverage report

### Testing AWS S3 Driver

[](#testing-aws-s3-driver)

- **Locally:** Valid AWS S3 credentials can be provided via `tests/.env` file, see `tests/.env.example` as an example. If no credentials are set, the AWS S3 tests will be skipped
- **CI**: Travis CI integration is performed by passing encrypted credentials in travis.yml (valid only for inakianduaga/eloquent-external-storage repo).
- [Amazon S3 testing in Travis CI](http://milesj.me/blog/read/amazon-s3-testing-travis-ci)

### Tests Coverage report

[](#tests-coverage-report)

- `gulp test --generateCoverage=coverageHtml` to generate html code coverage report (under `./coverage` folder)

Documentation generation
------------------------

[](#documentation-generation)

- The package code documentation can be generated by running `gulp docs`, which generates the docs in the `./docs` folder

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

4124d ago

### Community

Maintainers

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

---

Top Contributors

[![inakianduaga](https://avatars.githubusercontent.com/u/4490289?v=4)](https://github.com/inakianduaga "inakianduaga (5 commits)")

---

Tags

eloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/inakianduaga-eloquent-external-storage/health.svg)

```
[![Health](https://phpackages.com/badges/inakianduaga-eloquent-external-storage/health.svg)](https://phpackages.com/packages/inakianduaga-eloquent-external-storage)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[prettus/l5-repository

Laravel 5|6|7|8|9|10|11|12 - Repositories to the database layer

4.2k10.8M145](/packages/prettus-l5-repository)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k25.2M34](/packages/kirschbaum-development-eloquent-power-joins)

PHPackages © 2026

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