PHPackages                             sigep/eloquent-enhancements - 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. sigep/eloquent-enhancements

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

sigep/eloquent-enhancements
===========================

This package aims to provide extra functionalities to Laravel's Eloquent

0.2.6(7y ago)99414[1 issues](https://github.com/Cohros/eloquent-enhancements/issues)MITPHPPHP &gt;=7.0.0

Since Jul 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Cohros/eloquent-enhancements)[ Packagist](https://packagist.org/packages/sigep/eloquent-enhancements)[ RSS](/packages/sigep-eloquent-enhancements/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (20)Used By (0)

Eloquent Enhancements
=====================

[](#eloquent-enhancements)

[![Build Status](https://camo.githubusercontent.com/f64f75d68187db7a3aa0de63779b1604eca458577b48ed221aa26167fb8cbf5a/68747470733a2f2f7472617669732d63692e6f72672f436f68726f732f656c6f7175656e742d656e68616e63656d656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/cohros/eloquent-enhancements)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fd006f56b40271788ce982b5d166ba9c16495afefc7ae5d0a079d2ed0bdec93e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f436f68726f732f656c6f7175656e742d656e68616e63656d656e74732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Cohros/eloquent-enhancements/?branch=master)

This package aims to provide extra functionalities to Laravel's Eloquent. The functionalities, for now, are provided in form of traits, so you don't have to change your models structure.

Error
-----

[](#error)

This trait add two methods to your models.

```
use Sigep\EloquentEnhancements\Traits\Error
```

### setErrors

[](#seterrors)

Receives a MessageBag and set in `$errors` property. The `SaveAll` uses it to store errors and allow you to use them in your controllers or views.

```
setErrors(Illuminate\Support\MessageBag $errors)
```

### errors

[](#errors)

Returns errors setted by `setErrors()`. Create a empty MessageBag if errors is not defined.

```
errors()
```

SaveAll
-------

[](#saveall)

This tait add the ability to save related objects in just one call. For example, if you have a User model who is related to Phone model, in a hasMany relationship, you can save a user with many phones with just one method call.

```
use Sigep\EloquentEnhancements\Traits\SaveAll;
```

Consider the following models:

```
class User extends Eloquent
{
    use Sigep\EloquentEnhancements\Traits\Error;
    use Sigep\EloquentEnhancements\Traits\SaveAll;

    public function phones()
    {
        return $this->hasMany('Phone');
    }
}

class Phone extends Eloquent
{
    public function user()
    {
        return $this->belongsTo('User');
    }
}
```

> We strongly suggest that you use model's observers to validate your data and use the `setErrors()` to transport validation messages. Is the best way to validate related data when you use this trait.

You can create a user with two phones using the `createAll()` method.

```
$input = array(
    'name' => 'Bob',
    'email' => 'bob@gmail.com',
    'phones' => array (
        array('number' => '1111111'),
        array('number' => '2222222'),
    ),
);

$bob = new User();
$bob->createAll($input);
```

Note that we have a key with the name of the relationship that we create on User model. This is necessary so SaveAll knows which model are involved and how save your data. If everything is fine, `createAll` will return true. Else, will return false.

Now, if you need to edit a number using the User model (when you have a form that shows all data, for example), you can use the `saveAll()` method.

```
$input = array(
    'name' => 'Bob',
    'email' => 'bob@gmail.com',
    'phones' => array (
        array('id' => 1, 'number' => '111-1111'),
        array('id' => 2, 'number' => '222-2222'),
    ),
);

$bob = User::find(1); // assuming bob have the id = 1
$bob->saveAll($input);
```

See that we add the `id` from the number on the array. This is necessary so SaveAll knows that is not a new record, but an update.

You do something similar when you need to remove a related model. You just need to pass the `_delete` key:

```
$input = array(
    'name' => 'Bob',
    'email' => 'bob@gmail.com',
    'phones' => array (
        array('id' => 1, '_delete' => true),
    ),
);

$bob = User::find(1); // assuming bob have the id = 1
$bob->saveAll($input);
```

In this case, the phone `#1` will be removed. The other properties are not necessary, just the `id` and the `_delete` key.

`SaveAll` can handle BelongsToMany relationships to. You just have to use like the examples above. But that kind of relationship has one particularity. If the pivot table has more columns them just the foreign keys, you can create a Relationship Model to handle the validations (assuming that you are using model observers to do the validation like suggested before :) ).

> More examples soon.

\--

> Written with [StackEdit](https://stackedit.io/).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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 ~89 days

Recently: every ~233 days

Total

17

Last Release

2897d ago

PHP version history (2 changes)0.0.1PHP &gt;=5.4.0

0.2.5PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/447facbc5e980eabe3a34ff1bcf74d5aa742e122e54d8e22168c9264f7f171e3?d=identicon)[beeblebrox3](/maintainers/beeblebrox3)

---

Top Contributors

[![beeblebrox3](https://avatars.githubusercontent.com/u/767624?v=4)](https://github.com/beeblebrox3 "beeblebrox3 (54 commits)")[![f4usto](https://avatars.githubusercontent.com/u/1486888?v=4)](https://github.com/f4usto "f4usto (6 commits)")[![NetoBraghetto](https://avatars.githubusercontent.com/u/6883793?v=4)](https://github.com/NetoBraghetto "NetoBraghetto (3 commits)")

---

Tags

eloquentlaravelphplaraveleloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sigep-eloquent-enhancements/health.svg)

```
[![Health](https://phpackages.com/badges/sigep-eloquent-enhancements/health.svg)](https://phpackages.com/packages/sigep-eloquent-enhancements)
```

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)

PHPackages © 2026

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