PHPackages                             bedoya/has-data - 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. bedoya/has-data

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

bedoya/has-data
===============

Trait to manage dynamic JSON fields in Laravel Eloquent models

v1.1.6(1mo ago)029MITPHPPHP ^8.3CI passing

Since Jun 21Pushed 1mo agoCompare

[ Source](https://github.com/bedoya/has-data)[ Packagist](https://packagist.org/packages/bedoya/has-data)[ Docs](https://github.com/bedoya/has-data)[ RSS](/packages/bedoya-has-data/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

HasData
=======

[](#hasdata)

[![PHP Version](https://camo.githubusercontent.com/bf0eb0cc4034ed6ee7511df5198ab349716bfedf22e3786cf03ad19ded48e64a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75653f7374796c653d666c617426636f6c6f723d73756363657373)](https://camo.githubusercontent.com/bf0eb0cc4034ed6ee7511df5198ab349716bfedf22e3786cf03ad19ded48e64a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75653f7374796c653d666c617426636f6c6f723d73756363657373)[![Packagist Version](https://camo.githubusercontent.com/12dce064b1298cebae9a17f644ac0af88b788c0b63968243cc9c44b8318c7cd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6265646f79612f6861732d646174613f7374796c653d666c617426636f6c6f723d73756363657373)](https://camo.githubusercontent.com/12dce064b1298cebae9a17f644ac0af88b788c0b63968243cc9c44b8318c7cd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6265646f79612f6861732d646174613f7374796c653d666c617426636f6c6f723d73756363657373)[![License](https://camo.githubusercontent.com/5dafe5cf824aad213f91e770aa47cde821974d0738f18c5ef3ef5f8ede1d6db4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6265646f79612f6861732d646174613f7374796c653d666c617426636f6c6f723d73756363657373)](https://camo.githubusercontent.com/5dafe5cf824aad213f91e770aa47cde821974d0738f18c5ef3ef5f8ede1d6db4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6265646f79612f6861732d646174613f7374796c653d666c617426636f6c6f723d73756363657373)[![Tests](https://camo.githubusercontent.com/f95a21e90ca80d06a046f630af46f3594a4a2abab77cfc8ba1fa5d20c9ef19a5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6265646f79612f6861732d646174612f74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c617426636f6c6f723d73756363657373)](https://camo.githubusercontent.com/f95a21e90ca80d06a046f630af46f3594a4a2abab77cfc8ba1fa5d20c9ef19a5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6265646f79612f6861732d646174612f74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c617426636f6c6f723d73756363657373)

A Laravel trait to manage dynamic JSON fields (usually named `data`) in Eloquent models, with elegant access, flexible customization, and auto-save support.

---

📦 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require bedoya/has-data
```

Optionally, publish the configuration file:

```
php artisan vendor:publish --tag=has-data-config
```

🚀 Usage
-------

[](#-usage)

Add the trait to any Eloquent model that has a JSON column (default: `data`):

```
use Bedoya\HasData\Traits\HasData;

class Raffle extends Model
{
    use HasData;

    protected $casts = [
        'data' => 'array',
    ];
}
```

### ✅ Access data using dot notation

[](#-access-data-using-dot-notation)

```
$raffle->getData('grid.rows');        // returns 25
$raffle->getData('grid');             // returns [25, 40]
$raffle->setData('grid.cols', 40);    // sets the value and optionally saves
$raffle->hasData('grid.rows');        // returns true
```

⚙️ Configuration
----------------

[](#️-configuration)

Default config (`config/has-data.php`)

```
return [
    'database' => [
        'column-name' => 'data',    // default JSON column name
        'nullable'    => true,
        'casts'       => 'array',
    ],
    'auto_save' => true,            // auto-save after setData()
];
```

### 🧠 Per-model configuration

[](#-per-model-configuration)

You can override the JSON column or auto-save behavior per model.

**Custom column per model**

```
class Client extends Model
{
    use HasData;

    protected string $dataColumn = 'metadata';
    protected $casts = [
        'metadata' => 'array',
    ];
}
```

**Disable auto-save per model**

```
class Client extends Model
{
    use HasData;

    public bool $hasDataAutoSave = false;
}
```

If `hasDataAutoSave` is not set, it falls back to the global config.

🧪 Testing
---------

[](#-testing)

This package includes full test coverage using PestPHP. To run the tests:

```
composer test
```

🧱 Requirements
--------------

[](#-requirements)

- PHP 8.1+
- Laravel 10 or 11
- JSON-compatible database column (casted to array)

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/license/mit).

✍️ Author
---------

[](#️-author)

**Andrés Bedoya**

###  Health Score

44

—

FairBetter than 91% of packages

Maintenance93

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~66 days

Recently: every ~16 days

Total

6

Last Release

35d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

1.1.3PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/1d775e4b5e8bf33d0a4d6babd131e16c340b53c6f2a3f5e1673efc200f155ad3?d=identicon)[Bedoya](/maintainers/Bedoya)

---

Top Contributors

[![bedoya](https://avatars.githubusercontent.com/u/7798411?v=4)](https://github.com/bedoya "bedoya (14 commits)")

---

Tags

jsonlaraveldataeloquenttraitcastattribute

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/bedoya-has-data/health.svg)

```
[![Health](https://phpackages.com/badges/bedoya-has-data/health.svg)](https://phpackages.com/packages/bedoya-has-data)
```

###  Alternatives

[cybercog/laravel-love

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

1.2k322.4k1](/packages/cybercog-laravel-love)[esensi/model

The base model traits of Esensi

20067.0k1](/packages/esensi-model)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

392393.3k5](/packages/rtconner-laravel-likeable)[cybercog/laravel-nova-ban

A Laravel Nova banning functionality for your application.

40203.4k](/packages/cybercog-laravel-nova-ban)[cviebrock/eloquent-typecast

Trait for Eloquent models to force type-casting on retrieved values

2469.7k](/packages/cviebrock-eloquent-typecast)

PHPackages © 2026

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