PHPackages                             asseco-voice/laravel-remote-relations - 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. asseco-voice/laravel-remote-relations

ActiveLibrary

asseco-voice/laravel-remote-relations
=====================================

Laravel support for making relations between microservices

v5.2.2(4mo ago)66.9k↓100%2[5 PRs](https://github.com/asseco-voice/laravel-remote-relations/pulls)MITPHPPHP ^8.1CI passing

Since Feb 10Pushed 4mo ago5 watchersCompare

[ Source](https://github.com/asseco-voice/laravel-remote-relations)[ Packagist](https://packagist.org/packages/asseco-voice/laravel-remote-relations)[ RSS](/packages/asseco-voice-laravel-remote-relations/feed)WikiDiscussions master Synced 1mo ago

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

[![](https://github.com/asseco-voice/art/raw/main/evil_logo.png)](https://see.asseco.com)

Laravel remote relations
========================

[](#laravel-remote-relations)

This package enables creating relations locally from Eloquent models to remote services.

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

[](#installation)

Install the package through composer. It is automatically registered as a Laravel service provider, so no additional actions are required.

`composer require asseco-voice/laravel-remote-relations`

Setup
-----

[](#setup)

1. Run `php artisan migrate` to migrate the table.

Table consists of:

1. Local model type/id - polymorphic relation of local Eloquent models
2. Service - indicating a key which needs to be mapped to a certain service class
3. Remote model - plain string representing a model in a remote service (isn't Laravel specific)
4. Remote model ID - actual ID to which a relation is created
5. Acknowledged - date to verify if reverse relation was created

Out of the box no services are registered because the package doesn't know where to fetch related data from, so you need to provide services manually.

1. Publish the configuration with `php artisan vendor:publish --tag=asseco-remote-relations-config`
2. Create a new service class for remote service you'd like to make a relation to and make it extend `HasRemoteRelations` interface
3. Interface has 2 methods which are responsible for resolving a single relation or a collection of relations.
4. Resolving collections will always be done on a single model type (i.e. collection of users) on a single service so that you can resolve multiple models at once if possible.
5. Model IDs are of `string` type so that it supports non-numeric IDs as well.
6. Add the class to config under `services` key in the format `'service_name' => Service::class'`

Usage
-----

[](#usage)

Have your models use a `Relatable` trait which will provide an Eloquent relation to a `RemoteRelation` class, so you don't have to repeat yourself.

There are also several handy methods:

- `relate($service, $model, $id)` - to create a relation
- `relateQuietly($service, $model, $id)` - to create a relation suppressing all events which would usually be fired by creation of the relation.
- `unrelate($service, $model, $id)` - to remove a relation
- `unrelateQuietly($service, $model, $id)` - to remove a relation suppressing all events which would usually be fired by creation of the relation.

CRUD API
--------

[](#crud-api)

Standard API resource is published on `api/remote-relations` endpoint with standard CRUD routes.

Going on `api/remote-relations/many`, you can execute a POST request to store many relations at once.

Additionally, there is a `GET` `api/remote-relations/{remote_relation}/resolved` endpoint which will return a resolved relation.

Acknowledgement
---------------

[](#acknowledgement)

Initially when you create a remote relation from service A to service B, acknowledged attribute is `null`. When service B catches the event and creates the relation in its database, it should set the acknowledged attribute of a newly created row to `true` and communicate back to service A to set acknowledged attribute of original relation to `now()`.

Resolving relations programmatically
------------------------------------

[](#resolving-relations-programmatically)

You will probably want to have a class which knows how to resolve particular relations. To do that, have your SDK class implement a `HasRemoteRelations` interface and implement methods from it.

Once you do that, register that class in `services.php` under `sdk` key. Service name must be the name which you are storing in the DB when populating the `service` attribute.

### Example

[](#example)

Given the following configuration in `services.php`:

```
'some_remote_service' => [
    'sdk' => SomeRemoteService::class,
],

```

Having added a `Relatable` trait to your `User` model.

You can now call a `relate()` method on a single user instance like this:

```
$user->relate('some_remote_service', 'model_on_your_remote_service', 'id_of_a_model_on_your_remote_service');

```

Note that first parameter equals to the service key in the configuration. That is how package knows which service to use.

Resolving relations can be done for a single relation, or a collection of relations:

```
$user->remoteRelations->first()->resolve() // resolves a single relation
$user->remoteRelations->resolve() // resolves a relation collection

```

Extending the package
=====================

[](#extending-the-package)

Publishing the configuration will enable you to change package models as well as controlling how migrations behave. If extending the model, make sure you're extending the original model in your implementation.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance74

Regular maintenance activity

Popularity28

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 75.4% 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

Recently: every ~216 days

Total

24

Last Release

145d ago

Major Versions

v0.1.1 → v1.0.02021-03-30

v1.0.0 → v2.0.02021-03-31

v2.2.0 → v3.0.02021-12-23

v3.2.0 → v4.0.02022-05-05

v4.2.0 → v5.0.02023-08-08

PHP version history (4 changes)v0.1.0PHP ^7.4

v1.0.0PHP ^7.4 || ^8.0

v4.0.0PHP ^8.0

v5.0.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![Norgul](https://avatars.githubusercontent.com/u/11718157?v=4)](https://github.com/Norgul "Norgul (43 commits)")[![josip-milotic](https://avatars.githubusercontent.com/u/42002911?v=4)](https://github.com/josip-milotic "josip-milotic (7 commits)")[![ngaspari](https://avatars.githubusercontent.com/u/33628128?v=4)](https://github.com/ngaspari "ngaspari (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![AkronimBlack](https://avatars.githubusercontent.com/u/39061674?v=4)](https://github.com/AkronimBlack "AkronimBlack (1 commits)")[![assefvisic](https://avatars.githubusercontent.com/u/60132037?v=4)](https://github.com/assefvisic "assefvisic (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asseco-voice-laravel-remote-relations/health.svg)

```
[![Health](https://phpackages.com/badges/asseco-voice-laravel-remote-relations/health.svg)](https://phpackages.com/packages/asseco-voice-laravel-remote-relations)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

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