PHPackages                             brahmic/laravel-filler - 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. brahmic/laravel-filler

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

brahmic/laravel-filler
======================

Laravel Eloquent Database Filler

1.0.0(2y ago)015MITPHPCI passing

Since Jun 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/brahmic/laravel-filler)[ Packagist](https://packagist.org/packages/brahmic/laravel-filler)[ RSS](/packages/brahmic-laravel-filler/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Laravel Eloquent Database Filler
================================

[](#laravel-eloquent-database-filler)

[🇷🇺 Документация на русском языке](readme_ru.md)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4a021de42a51c7b540070ca2fd202ccfb1576483992e6397fb85259009ce9647/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f627261686d69632f6c61726176656c2d66696c6c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/brahmic/laravel-filler)[![GitHub Tests Action Status](https://camo.githubusercontent.com/2c1b9e63e267e6d8a4a79e78ad6bf34198dd97f9cb008d26ce8b2fb30016130e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f627261686d69632f6c61726176656c2d66696c6c65722f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/brahmic/laravel-filler/actions?query=workflow%3Arun-tests+branch%3Amaster)

Contents
--------

[](#contents)

- [Introduction](#introduction)
- [Package Features](#package-features)
- [Limitations](#limitations)
- [Installation](#installation)
- [Usage](#usage)
    - [Backend Example](#backend-example)
    - [Frontend Example](#frontend-example)
- [Supported Relationships](#supported-relationships)
    - [Flat Entities](#flat-entities)
    - [HasOne](#hasone)
    - [HasMany](#hasmany)
    - [BelongsTo](#belongsto)
    - [BelongsToMany](#belongstomany)
    - [MorphTo](#morphto)
    - [MorphOne](#morphone)
    - [MorphMany](#morphmany)
    - [MorphToMany](#morphtomany)
    - [MorphedByMany](#morphedbymany)
    - [HasOneThrough](#hasonethrough)
    - [HasManyThrough](#hasmanythrough)
- [Output Features](#output-features)
- [Best Practices](#best-practices)
- [Testing](#testing)

Introduction
------------

[](#introduction)

Laravel Eloquent Database Filler is a package for Laravel that solves the problem of automatically hydrating Eloquent models along with nested relationships based on data received from API requests.

### Problem Statement

[](#problem-statement)

When working with data via API, we often receive and send entities with nested relationships. Laravel provides convenient mechanisms for working with relationships when receiving data, but when sending and updating data with nested relationships, these nested structures have to be processed manually. This requires writing a lot of code for:

1. Creating new records in the database
2. Updating existing records
3. Deleting records that are no longer needed
4. Maintaining the integrity of relationships between models

This package automates the entire process of saving complex nested structures to the database, allowing you to work with API data "as is", without the need for manual processing.

Package Features
----------------

[](#package-features)

- **Work with models "as is"** - no additional data transformations required before saving to the database
- **Unit of Work** - all changes are applied atomically; either all changes will be made, or (in case of an error) no changes will be made at all
- **Identity Map** - guarantees that entities of the same type and with the same identifier are essentially the same object
- **UUID** - allows you to create valid entities and link them together by identifier without accessing the database
- **Recursive processing** - supports arbitrary level of relationship nesting
- **Automatic relationship loading** - all passed relationships are automatically added to the entity as loaded relationships

Limitations
-----------

[](#limitations)

In the current version, the package only works with models that use UUID as the primary key.

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

[](#installation)

```
composer require brahmic/laravel-filler
```

After installation, the package will be automatically registered in Laravel through the package auto-discovery mechanism.

Usage
-----

[](#usage)

The package is very easy to use. Main steps:

1. Inject the `Filler` service through dependency injection
2. Use the `fill` method to populate the model with data
3. Call the `flush` method to save all changes to the database

### Backend Example

[](#backend-example)

```
