PHPackages                             pion/laravel-support-eloquent - 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. pion/laravel-support-eloquent

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

pion/laravel-support-eloquent
=============================

Package with small support traits and classes for the Laravel Eloquent models

v1.5.0(1mo ago)37.2k—9.5%1[1 PRs](https://github.com/pionl/laravel-support-eloquent/pulls)MITPHPPHP ^8.0

Since May 4Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/pionl/laravel-support-eloquent)[ Packagist](https://packagist.org/packages/pion/laravel-support-eloquent)[ Fund](https://revolut.me/martinpv7n)[ GitHub Sponsors](https://github.com/pionl)[ RSS](/packages/pion-laravel-support-eloquent/feed)WikiDiscussions master Synced 2w ago

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

Laravel's Eloquent support package
==================================

[](#laravels-eloquent-support-package)

Contains a set of traits for the eloquent model. In future can contain more set of classes/traits for the eloquent database.

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

[](#installation)

```
composer require pion/laravel-support-eloquent

```

Attribute value altering traits
-------------------------------

[](#attribute-value-altering-traits)

Set of traits that will change the attribute value.

### CleanHTMLFromAttributeTrait

[](#cleanhtmlfromattributetrait)

Enables automatic attribute value cleaning from HTML for all attributes, by limiting only desired by `$cleanAttributes`property or by limiting which attributes can have html `$dontCleanAttributes`. You can use the `$stripHtmlTags` property to specify tags which should not be stripped.

For manual usage use `CleanHTMLTrait` with `tryToCleanAttributeValue($key, $value)` method.

#### Null only given attributes:

[](#null-only-given-attributes)

```
public $cleanAttributes = [
    "name"
];
```

#### Don't null provided attributes:

[](#dont-null-provided-attributes)

```
public $dontCleanAttributes = [
    "name"
];
```

### NullEmptyStringAttributeTrait

[](#nullemptystringattributetrait)

Enables the automatic nulling of empty string value (like from post or set). You can provide list of columns keys to allow only specified columns (use `$nullEmptyAttributes`) to be set to null or you can provide a list of columns keys to ignore while trying to null the value (use `$dontNullEmptyAttributes`). They can be set in construct or as property.

For manual usage use `NullEmptyStringTrait` with `tryToNullAttributeValue($key, $value)` method.

#### Null only given attributes:

[](#null-only-given-attributes-1)

```
public $nullEmptyAttributes = [
    "name"
];
```

#### Don't null provided attributes:

[](#dont-null-provided-attributes-1)

```
public $dontNullEmptyAttributes = [
    "name"
];
```

### NormalizeFloatAttributeTrait

[](#normalizefloatattributetrait)

Converts float string to float value with comma support (floatval fails to convert 13,3 to 13.3) by setting list of attributes via `$normalizeFloatAttributes`.

```
public $normalizeFloatAttributes = [
    'price',
    'discount',
];

```

For manual usage use `NormalizeFloatTrait ` with `tryToNormalizeFloatAttributeValue($key, $value)` method.

### DateAttributeValueTrait

[](#dateattributevaluetrait)

Converts allowed attributes (by settings `$dateAttributes`) to carbon instance without any format limitation. Tries to parse any format.

```
public $dateAttributes = ['custom_date'];
```

For manual usage use `DateAttributeTrait` with `tryToConvertAttributeValueToDate($key, $value)` method.

All values are converted via `toArray` method to default format. You can customize date formats by attribute by setting `dateFormats`:

```
public $dateFormats = [
    'born' => 'Y-m-d'
];
```

### Running multiple trait functions

[](#running-multiple-trait-functions)

#### Using all attributes traits

[](#using-all-attributes-traits)

To apply all traits that are currently implemented use `AlterAttributeValueTrait`.

#### Manual

[](#manual)

Unfortunately traits can't override same method (in this case `setAttribute`). For this purpose, you must override the `setAttribute`method by your self and call the desired trait method by your self.

Every trait has own **manual** method that tries to alter the value. Use appropriate trait (`NullEmptyStringTrait`, `CleanHTMLTrait`, etc).

For chaining the value you can use helper function `alter_attribute_value`.

```
/**
 * Set a given attribute on the model.
 *
 * @param  string $key
 * @param  mixed  $value
 */
public function setAttribute($key, $value)
{
    parent::setAttribute($key, alter_attribute_value($key, $value, $this, [
        'tryToCleanAttributeValue',
        'tryToNullAttributeValue'
    ]));
}
```

Relation Traits
---------------

[](#relation-traits)

### RelationJoinTrait

[](#relationjointrait)

Enables to create a join SQL statement that will construct the relation model and stores it into relations (so you don't need to eager load the relation). The model is created from the relation function (the key you provide). You can create a custom aliases to fix custom relation naming.

In default usage will load all columns from schema, for better perfomance you can provide a set of columns to load from the relation. You can't provide a '\*' as column.

`$relationAliases` - A list of relations that has different method name than the table.

Can be defined in model like this:

```
protected $relationAliases = [
    "activity_type" => "type"
];
```

Then you can call it in standard way `modelJoin("type")` for a ActivityType model class.

#### Example

[](#example)

The basic method support custom columns, where condition, join operator and join type.

##### All columns

[](#all-columns)

```
Model::modelJoin("type")->get()
```

##### Desired columns (recommended)

[](#desired-columns-recommended)

```
Model::modelJoin("type", ["name", "id", "color"])->get();
```

Then you can get the object by standard relation way:

```
$model->type->color
```

But be carefull, can be null (default is LEFT connection)!

##### Desired columns with inner join

[](#desired-columns-with-inner-join)

```
Model::modelJoin("type", ["name", "id", "color"], "inner")->get();
```

##### Method

[](#method)

Docs is provided in code.

```
modelJoin($query, $relation_name, $operatorOrColumns = '=', $type = 'left', $where = false, $columns = array())
```

#### Advanced example

[](#advanced-example)

Docs is provided in code. Uses table as a relation function.

```
joinWithSelect($query, $table, $one, $operatorOrColumns, $two, $type = "left", $where = false, $columns = array())
```

### RelationCountTrait

[](#relationcounttrait)

Enables to count a related models. In future will prepare better docs.

#### Example

[](#example-1)

Usage of where:

```
$count = $model->relationCountWithWhere("user_permission", "user_id", $user, "App\\Models\\User");
```

Calling the function again will use the cache in relations array. After this call you can also use

```
$model->user_permission_{ForeignKey}_{userIdValueForWhere} which will the object of User model with count attribute.
```

You can also get the where index by passing variable which will be overided by the reference:

```
$index = "user_permission";
$model->relationCountWithWhere($index, "user_id", $user, "App\\Models\\User");
```

Simple call will return count and the index will be stored in $model-&gt;user

```
$model->relationCount("user", "App\\Models\\User")
```

Testing
-------

[](#testing)

Run the full support matrix and get a pass/fail table:

```
bin/test-matrix.sh
```

Run the PHPUnit suite in Docker for each supported PHP runtime:

```
docker compose run --rm php82 composer test
docker compose run --rm php83 composer test
docker compose run --rm php85 composer test
```

Resolve and test a specific Laravel database line inside Docker:

```
docker compose run --rm php82 bin/test-target.sh '^9.0'
docker compose run --rm php82 bin/test-target.sh '^10.0'
docker compose run --rm php83 bin/test-target.sh '^11.0'
docker compose run --rm php83 bin/test-target.sh '^12.0'
docker compose run --rm php85 bin/test-target.sh '^13.0'
```

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance91

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 75.9% 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 ~218 days

Recently: every ~401 days

Total

18

Last Release

44d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad0f2a11e630f5f386cb8544d42f0c56c2b89258172dae581a33dddcc5de1d83?d=identicon)[pionl](/maintainers/pionl)

---

Top Contributors

[![pionl](https://avatars.githubusercontent.com/u/1878831?v=4)](https://github.com/pionl "pionl (22 commits)")[![jakubdibala](https://avatars.githubusercontent.com/u/7672104?v=4)](https://github.com/jakubdibala "jakubdibala (5 commits)")[![cibot-pionl](https://avatars.githubusercontent.com/u/299922687?v=4)](https://github.com/cibot-pionl "cibot-pionl (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

eloquenthtmlhtml-cleanerlaravellaravel-5-packagenullablerelational-modeltrait

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pion-laravel-support-eloquent/health.svg)

```
[![Health](https://phpackages.com/badges/pion-laravel-support-eloquent/health.svg)](https://phpackages.com/packages/pion-laravel-support-eloquent)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.2k45.4M704](/packages/spatie-laravel-medialibrary)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M110](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k35.7M52](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.6M2](/packages/glushkovds-phpclickhouse-laravel)

PHPackages © 2026

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