{"id":22682197,"url":"https://github.com/mits87/eloquent-nested-attributes","last_synced_at":"2025-04-12T17:24:14.740Z","repository":{"id":52971571,"uuid":"101763983","full_name":"mits87/eloquent-nested-attributes","owner":"mits87","description":"Nested attributes allow you to save attributes on associated records through the parent.","archived":false,"fork":false,"pushed_at":"2024-05-03T10:06:37.000Z","size":32,"stargazers_count":13,"open_issues_count":0,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T11:44:52.829Z","etag":null,"topics":["eloquent","laravel","lumen","nested-attributes"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mits87.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-29T13:23:43.000Z","updated_at":"2024-05-03T10:06:42.000Z","dependencies_parsed_at":"2024-12-09T20:27:02.363Z","dependency_job_id":"777efa69-c1d2-4755-9f48-cba554599b97","html_url":"https://github.com/mits87/eloquent-nested-attributes","commit_stats":{"total_commits":23,"total_committers":5,"mean_commits":4.6,"dds":"0.26086956521739135","last_synced_commit":"0e90a3c906fd97985144ca2cb35ea015bd44590a"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Feloquent-nested-attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Feloquent-nested-attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Feloquent-nested-attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Feloquent-nested-attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mits87","download_url":"https://codeload.github.com/mits87/eloquent-nested-attributes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248603000,"owners_count":21131719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","laravel","lumen","nested-attributes"],"created_at":"2024-12-09T20:25:45.906Z","updated_at":"2025-04-12T17:24:14.718Z","avatar_url":"https://github.com/mits87.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eloquent-nested-attributes\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-travis]][link-travis]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nNested 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.\n\n## Structure\n\nIf any of the following are applicable to your project, then the directory structure should follow industry best practises by being named the following.\n\n```\nsrc/\ntests/\nvendor/\n```\n\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require mits87/eloquent-nested-attributes\n```\n\n## Usage\n\n``` php\nnamespace App;\n\nuse Eloquent\\NestedAttributes\\Model;\n\nclass Post extends Model\n{\n    protected $fillable = ['title'];\n    \n    protected $nested = ['option', 'comments'];\n\n    public function option() {\n        //it can be also morphOne\n        return $this-\u003ehasOne('App\\Option');\n    }\n\n    public function comments() {\n        //it can be also morphMany\n        return $this-\u003ehasMany('App\\Comment');\n    }\n}\n```\n\nor\n\n``` php\nnamespace App;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Eloquent\\NestedAttributes\\Traits\\HasNestedAttributesTrait;\n\nclass Post extends Model\n{\n    use HasNestedAttributesTrait;\n\n    ...\n}\n```\n\nusage:\n\n``` php\n\\App\\Post::create([\n    'title' =\u003e 'Some text',\n\n    'option' =\u003e [\n        'info' =\u003e 'some info'\n    ],\n\n    'comments' =\u003e [\n        [\n            'text' =\u003e 'Comment 1'\n        ], [\n            'text' =\u003e 'Comment 2'\n        ],\n    ]\n]);\n\n\n\\App\\Post::findOrFail(1)-\u003eupdate([\n    'title' =\u003e 'Better text',\n\n    'option' =\u003e [\n        'info' =\u003e 'better info'\n    ],\n\n    'comments' =\u003e [\n        [\n            'id' =\u003e 2,\n            'text' =\u003e 'Comment 2'\n        ],\n    ]\n]);\n```\n\nto delete nested row you should pass `_destroy` attribute:\n\n``` php\n\\App\\Post::findOrFail(1)-\u003eupdate([\n    'title' =\u003e 'Better text',\n\n    'option' =\u003e [\n        'info' =\u003e 'better info'\n    ],\n\n    'comments' =\u003e [\n        [\n            'id' =\u003e 2,\n            '_destroy' =\u003e true\n        ],\n    ]\n]);\n```\n\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email mits87@gmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Piotr Krajewski][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/mits87/eloquent-nested-attributes.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/mits87/eloquent-nested-attributes/master.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/mits87/eloquent-nested-attributes.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/mits87/eloquent-nested-attributes\n[link-travis]: https://travis-ci.org/mits87/eloquent-nested-attributes\n[link-downloads]: https://packagist.org/packages/mits87/eloquent-nested-attributes\n[link-author]: https://github.com/mits87\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmits87%2Feloquent-nested-attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmits87%2Feloquent-nested-attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmits87%2Feloquent-nested-attributes/lists"}