PHPackages                             denizgolbas/eloquent-save-together - 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. denizgolbas/eloquent-save-together

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

denizgolbas/eloquent-save-together
==================================

For Laravel Eloquent that makes it easy to save related models together.

v1.0.0(5mo ago)21[1 PRs](https://github.com/denizgolbas/eloquent-save-together/pulls)MITPHPPHP ^8.2|^8.3CI passing

Since Dec 2Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/denizgolbas/eloquent-save-together)[ Packagist](https://packagist.org/packages/denizgolbas/eloquent-save-together)[ Docs](https://github.com/denizgolbas/eloquent-save-together)[ GitHub Sponsors](https://github.com/denizgolbas)[ RSS](/packages/denizgolbas-eloquent-save-together/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (3)Used By (0)

[![logo.png](art/logo.png)](art/logo.png)

Eloquent SaveTogether
=====================

[](#eloquent-savetogether)

[![Latest Version on Packagist](https://camo.githubusercontent.com/50fc4c581e2ff521651ccff2718822a9944f3a1a26cd40219b187ac34ff854c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64656e697a676f6c6261732f656c6f7175656e742d736176652d746f6765746865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/denizgolbas/eloquent-save-together)[![GitHub Tests Action Status](https://camo.githubusercontent.com/49f74a4cc0f10bf485671f685c61922cd9cf480a9ebf9da073fecb06289ddd80/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64656e697a676f6c6261732f656c6f7175656e742d736176652d746f6765746865722f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/denizgolbas/eloquent-save-together/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/cc03ec718163fbf773019013672452afdeac1b18e59ca8cd20df50e5dfb1a003/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64656e697a676f6c6261732f656c6f7175656e742d736176652d746f6765746865722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/denizgolbas/eloquent-save-together/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/d60e60ac502dc852a779dbf8d2f3c717ff6b39f14846f4784579acb08b39316c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64656e697a676f6c6261732f656c6f7175656e742d736176652d746f6765746865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/denizgolbas/eloquent-save-together)

A powerful Laravel package that allows you to save Eloquent models along with all their relationships in a single operation. Perfect for handling complex nested data structures from API requests or forms.

Features
--------

[](#features)

- 🚀 Save parent and all related models with one method call
- 🔄 Automatic handling of create/update operations based on ID presence
- 🗑️ Smart deletion of removed related records
- 🌳 Support for deeply nested relationships
- ⚡ Clean and intuitive API
- 🎯 Type-safe with full IDE support

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

[](#installation)

You can install the package via composer:

```
composer require denizgolbas/eloquent-save-together
```

Optionally, you can publish the config file to define custom relation mappings:

```
php artisan vendor:publish --tag="eloquent-save-together-config"
```

Basic Usage
-----------

[](#basic-usage)

### 1. Add the trait to your model

[](#1-add-the-trait-to-your-model)

```
