PHPackages                             tusimo/embed-relation - 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. tusimo/embed-relation

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

tusimo/embed-relation
=====================

a relation for laravel

v0.3(7y ago)310.0k↓23.1%MITPHP

Since Sep 13Pushed 6y agoCompare

[ Source](https://github.com/tusimo/embed-relation)[ Packagist](https://packagist.org/packages/tusimo/embed-relation)[ Docs](https://github.com/tusimo/embed-relation)[ RSS](/packages/tusimo-embed-relation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (7)Used By (0)

embed-relation [![Latest Stable Version](https://camo.githubusercontent.com/f862231026eca5b00d58a4fc1d9693c16d6cf86feeae3ba8d87b9b8695098820/687474703a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f747573696d6f2f656d6265642d72656c6174696f6e2e737667)](https://packagist.org/packages/tusimo/embed-relation) [![Total Downloads](https://camo.githubusercontent.com/963a5baeb5969a9c7a43a48781fd82159edacd8b0eb5f1df0d326a9ea39b547c/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f747573696d6f2f656d6265642d72656c6174696f6e2e737667)](https://packagist.org/packages/tusimo/embed-relation)
==========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#embed-relation-)

add a new relation is missing from [Laravel](https://laravel.com/)'s ORM. embedsMany extends [Eloquent](https://laravel.com/docs/master/eloquent) ORM .

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

[](#installation)

Either [PHP](https://php.net) 5.6+ is required.

To get the latest version of embedsMany, simply require the project using [Composer](https://getcomposer.org):

```
$ composer require tusimo/embed-relation
```

Instead, you may of course manually update your require block and run `composer update` if you so choose:

```
{
    "require": {
        "tusimo/embed-relation": "^0.1"
    }
}
```

Usage
-----

[](#usage)

Within your eloquent model class add following line And when we have a json string column as data. We support virtual column and can use cast. And support some new cast, 'integer\_array', 'string\_array', 'float\_array', 'bool\_array'

```
class User extends Model {
    use \Tusimo\Eloquent\Traits\EmbedsRelation;
    use \Tusimo\Eloquent\Traits\CastAttributes;

    protected $virtualColumnMaps = [
        'data' => [
            'address' => 'home_address',//you can rename the column
            'follower_ids'
        ],
        //'more_json_data' => [],
    ];

    protected $casts = [
        'book_ids' => 'integer_array',
        'home_address' => 'string',
        'follower_ids' => 'integer_array',
    ];
    ...
}
```

Example:
--------

[](#example)

Consider User has several favorite books and the book\_ids just store in the user table as book\_ids column. We want this column can to load use relations. So we can do it like this. We have user table just like this.

iduser\_namebook\_idsdata1tusimo1,2,3{"address":"NY","follower\_ids":"1,3"}2john2,4,7{"address":"WD","follower\_ids":"3"}3aly5{"address":"LA","follower\_ids":"1,2"}and book table like this,

idbook1css2php3javascript4database5sql6python7html```
class User extends Model {
    use \Tusimo\Eloquent\Traits\EmbedsRelation;

    public function books () {
        return $this->embedsMany(Book::class);
    }
}
```

If we want to get the books so we can use`$user->books`. For now I just finished get relation data. Next I will do the save thing And the reverse relation.

Now we can access data like this .

```
    $user->home_address = 'HA';
    $user->follower_ids = [1,2,3,4];
    $user->save();
    foreach($user->follower_ids as $followerId) {//which now is array type
        echo $followerId;
    }
    if($user->isVirtualDirty('home_address')) {
        //detect virtual column is dirty or not
        dd($user->getVirtualDirty());
    }
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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 ~77 days

Total

5

Last Release

2726d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/05d5a0db1ead85cb05385aef0414b26e260d53a6d8e1cab0f74d884f5c872d39?d=identicon)[tusimo](/maintainers/tusimo)

---

Top Contributors

[![tusimo](https://avatars.githubusercontent.com/u/4344635?v=4)](https://github.com/tusimo "tusimo (15 commits)")

---

Tags

laraveldatabasemodeleloquent

### Embed Badge

![Health badge](/badges/tusimo-embed-relation/health.svg)

```
[![Health](https://phpackages.com/badges/tusimo-embed-relation/health.svg)](https://phpackages.com/packages/tusimo-embed-relation)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[friendsofcat/laravel-couchbase

A Couchbase based Eloquent model and Query builder for Laravel

1430.8k](/packages/friendsofcat-laravel-couchbase)

PHPackages © 2026

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