New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

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.
364 12

Larablocks Analysis

mits87/eloquent-nested-attributes works with Laravel 5 (latest release 0.0.6, Nov 23, 2017), which reached end of life: no more fixes, even for security.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 5, past end of life
  • No release in the last 12 months (last: Nov 23, 2017)
  • 0 downloads a month (needs 10,000)
  • 12 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Nov 23, 2017.
  • No releases in the last 12 months.
  • First released: Aug 29, 2017.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 28, 2026.

Install
composer require mits87/eloquent-nested-attributes
Latest Version:0.0.6
PHP:>=7.0
Laravel:5
License:MIT
Last Updated:May 3, 2024
Links: GitHub  ·  Packagist
Maintainer: mits

eloquent-nested-attributes

Latest Version on Packagist Software License Build Status Total Downloads

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

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

Via Composer

$ composer require mits87/eloquent-nested-attributes

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

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

shaozeming/laravel-elasticsearch

Maps Laravel and lumen Eloquent models to Elasticsearch types.

1,335 2
cacing69/bitbuilder

Make easy query builder / eloquent queries based on requests for API Response

72 1
tuuke/laravel-rest

Fully fledged REST system integrated with Laravel and Lumen.

1 0
veelasky/laravel-hashid

HashId Implementation on Laravel Eloquent ORM

274,916 48
ekmungai/eloquent-ifrs

Eloquent Double Entry Accounting with focus on IFRS Compliant Reporting

74,138 367

Version History

Version Released PHP Laravel License
0.0.6 >=7.0 ~5.1 MIT
0.0.4 >=7.0 ~5.1 MIT
0.0.3 >=7.0 ~5.1 MIT
0.0.2 ~5.6|~7.0 ~5.1 MIT
0.0.1 ~5.6|~7.0 ~5.1 MIT