PHPackages                             engency/eloquent-formatting - 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. engency/eloquent-formatting

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

engency/eloquent-formatting
===========================

Eloquent Custom Formatting

v0.4.1(2y ago)04.5k1MITPHPPHP ^7.4|^8.0

Since Sep 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Engency/eloquent-formatting)[ Packagist](https://packagist.org/packages/engency/eloquent-formatting)[ RSS](/packages/engency-eloquent-formatting/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (1)

Eloquent Custom Formatting
==========================

[](#eloquent-custom-formatting)

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

[](#requirements)

- PHP 7.1+
- Eloquent 7.0+
- Carbon

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

[](#installation)

You may use composer to install the eloquent-formatting plugin into your Laravel project;

```
composer require engency/eloquent-formatting
```

Use the CustomDataFormats trait and the ExportsCustomDataFormats interface on your model classes;

```
namespace App\Models;

use Engency\DataStructures\CustomDataFormats;
use Engency\DataStructures\ExportsCustomDataFormats;
use Illuminate\Database\Eloquent\Model;

Class User extends Model implements ExportsCustomDataFormats
{
   use CustomDataFormats;

    protected $exports = [
        'default' => [
            'name',
            'age',
            ['posts', ['format' => 'extended']],
            ['created_at', ['dateFormat' => 'yy-m-d']]
        ],
        'limited' => [
            'name'
        ]
    ];

    public function posts() {
        return $this->hasMany(Post::class);
    }

}

Class Post extends Model implements ExportsCustomDataFormats
{
   use CustomDataFormats;

    protected $exports = [
        'default' => [
            'name',
        ],
        'extended' => [
            'name',
            'created_at'
        ]
    ];

}
```

Using the `$exports` field, you can specify which attributes should be exported in which situation. Have a look at the User class. The instance exports its name, age, posts and created\_at date by default.

### Basic usage

[](#basic-usage)

```
$user = User::find(1);
$array = $user->toArray(); // exports name, age, posts and created_at
$limited_array = $user->toArray('limited'); // exports only the name-attribute
```

### Exporting relations or collections

[](#exporting-relations-or-collections)

The user class above shows a one-to-many relation between the user and post class. Since the Post class also implements the ExportsCustomDataFormats interface, we can define the desired format.

```
['posts', ['format' => 'extended']]
```

### Exporting date attributes

[](#exporting-date-attributes)

You can choose in which format a Carbon date attribute should be exported. For more information on date formatting, have a look at the Carbon documentation:

```
['created_at', ['dateFormat' => 'yy-m-d']]
```

Contributors
------------

[](#contributors)

- Frank Kuipers ([GitHub](https://github.com/frankkuipers))

License
-------

[](#license)

This plugin is licenced under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

28

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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

Every ~353 days

Total

5

Last Release

746d ago

PHP version history (2 changes)v0.1PHP &gt;=7.1

v0.4.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1830445?v=4)[Frank Kuipers](/maintainers/frankkuipers)[@frankkuipers](https://github.com/frankkuipers)

---

Top Contributors

[![frankkuipers](https://avatars.githubusercontent.com/u/1830445?v=4)](https://github.com/frankkuipers "frankkuipers (10 commits)")

---

Tags

laravelmodeleloquentformattingdata structure

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/engency-eloquent-formatting/health.svg)

```
[![Health](https://phpackages.com/badges/engency-eloquent-formatting/health.svg)](https://phpackages.com/packages/engency-eloquent-formatting)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M107](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k35.7M51](/packages/kirschbaum-development-eloquent-power-joins)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k5.2M37](/packages/tucker-eric-eloquentfilter)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

592459.5k2](/packages/spiritix-lada-cache)[esensi/model

The base model traits of Esensi

20167.1k1](/packages/esensi-model)

PHPackages © 2026

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