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.5k↓35.6%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 today

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 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

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

2773d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4344635?v=4)[tusimo](/maintainers/tusimo)[@tusimo](https://github.com/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.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)

PHPackages © 2026

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