PHPackages                             joaoroyosilva/eloquent-nested-attributes - 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. joaoroyosilva/eloquent-nested-attributes

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

joaoroyosilva/eloquent-nested-attributes
========================================

Nested attributes allow you to save attributes on associated records through the parent. By default nested attribute updating is turned off and you can enable it using the $nested attribute. When you enable nested attributes an attribute writer is defined on the model.

1.0.3(3y ago)0374↓100%1MITPHPPHP &gt;=7.2

Since Aug 29Pushed 1y agoCompare

[ Source](https://github.com/joaoroyosilva/eloquent-nested-attributes)[ Packagist](https://packagist.org/packages/joaoroyosilva/eloquent-nested-attributes)[ Docs](https://github.com/mits87/eloquent-nested-attributes)[ RSS](/packages/joaoroyosilva-eloquent-nested-attributes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (7)Used By (0)

eloquent-nested-attributes
==========================

[](#eloquent-nested-attributes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fed84034f77aab8fe8359c29367b1ef86a0f154e5b832077be3cf0f5701af9e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d69747338372f656c6f7175656e742d6e65737465642d617474726962757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mits87/eloquent-nested-attributes)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/0ee07d70908860a920a61e53d63dcf73a1668a6955fb5f5aaa77032a41fb97fe/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d69747338372f656c6f7175656e742d6e65737465642d617474726962757465732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/mits87/eloquent-nested-attributes)[![Total Downloads](https://camo.githubusercontent.com/a68ab1cef80f45516b2871fbdf5cd0d9f2e9fdcc7edd9f6890ad5a3fcf1015ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d69747338372f656c6f7175656e742d6e65737465642d617474726962757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mits87/eloquent-nested-attributes)

\*\*Forked from mits87/eloquent-nested-attributes

Nested attributes allow you to save attributes on associated records through the parent. By default nested attribute updating is turned off and you can enable it using the $nested attribute. When you enable nested attributes an attribute writer is defined on the model.

Structure
---------

[](#structure)

If any of the following are applicable to your project, then the directory structure should follow industry best practises by being named the following.

```
src/
tests/
vendor/

```

Install
-------

[](#install)

Via Composer

```
$ composer require mits87/eloquent-nested-attributes
```

Usage
-----

[](#usage)

```
namespace App;

use Eloquent\NestedAttributes\Model;

class Post extends Model
{
    protected $fillable = ['title'];

    protected $nested = ['option', 'comments'];

    public function option() {
        //it can be also morphOne
        return $this->hasOne('App\Option');
    }

    public function comments() {
        //it can be also morphMany
        return $this->hasMany('App\Comment');
    }
}
```

or

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Eloquent\NestedAttributes\Traits\HasNestedAttributesTrait;

class Post extends Model
{
    use HasNestedAttributesTrait;

    ...
}
```

usage:

```
\App\Post::create([
    'title' => 'Some text',

    'option' => [
        'info' => 'some info'
    ],

    'comments' => [
        [
            'text' => 'Comment 1'
        ], [
            'text' => 'Comment 2'
        ],
    ]
]);

\App\Post::findOrFail(1)->update([
    'title' => 'Better text',

    'option' => [
        'info' => 'better info'
    ],

    'comments' => [
        [
            'id' => 2,
            'text' => 'Comment 2'
        ],
    ]
]);
```

to delete nested row you should pass `_destroy` attribute:

```
\App\Post::findOrFail(1)->update([
    'title' => 'Better text',

    'option' => [
        'info' => 'better info'
    ],

    'comments' => [
        [
            'id' => 2,
            '_destroy' => true
        ],
    ]
]);
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Piotr Krajewski](https://github.com/mits87)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~394 days

Recently: every ~493 days

Total

6

Last Release

1204d ago

Major Versions

0.0.6 → 1.0.32023-01-24

PHP version history (3 changes)0.0.1PHP ~5.6|~7.0

0.0.3PHP &gt;=7.0

1.0.3PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6483d84c2fa7219b589aaad137d418b9ad6bf10c83f0177e2c7f5eee10060d94?d=identicon)[joaoroyosilva](/maintainers/joaoroyosilva)

---

Top Contributors

[![joaoroyosilva](https://avatars.githubusercontent.com/u/6354258?v=4)](https://github.com/joaoroyosilva "joaoroyosilva (12 commits)")[![mits87](https://avatars.githubusercontent.com/u/605186?v=4)](https://github.com/mits87 "mits87 (4 commits)")

---

Tags

laravellumeneloquentNested Attributes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/joaoroyosilva-eloquent-nested-attributes/health.svg)

```
[![Health](https://phpackages.com/badges/joaoroyosilva-eloquent-nested-attributes/health.svg)](https://phpackages.com/packages/joaoroyosilva-eloquent-nested-attributes)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)

PHPackages © 2026

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