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)03761MITPHPPHP &gt;=7.2

Since Aug 29Pushed 1w 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 3w 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

40

—

FairBetter than 86% of packages

Maintenance64

Regular maintenance activity

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

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

1249d 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://avatars.githubusercontent.com/u/6354258?v=4)[João Gabriel Royo da Silva](/maintainers/joaoroyosilva)[@joaoroyosilva](https://github.com/joaoroyosilva)

---

Top Contributors

[![joaoroyosilva](https://avatars.githubusercontent.com/u/6354258?v=4)](https://github.com/joaoroyosilva "joaoroyosilva (13 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

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M88](/packages/mongodb-laravel-mongodb)[spatie/laravel-sluggable

Generate slugs when saving Eloquent models

1.5k12.4M294](/packages/spatie-laravel-sluggable)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[watson/validating

Eloquent model validating trait.

9733.4M53](/packages/watson-validating)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)

PHPackages © 2026

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