PHPackages                             4myth/api - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. 4myth/api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

4myth/api
=========

Synchronizing data between Laravel's framework

v1.0.2(6y ago)1285MITPHPPHP &gt;=7.1

Since Apr 6Pushed 6y ago1 watchersCompare

[ Source](https://github.com/mythpe/api-manager)[ Packagist](https://packagist.org/packages/4myth/api)[ RSS](/packages/4myth-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

MyTh API Manager
----------------

[](#myth-api-manager)

[![Latest Stable Version](https://camo.githubusercontent.com/1b4a288304848197b6ff1c58143fc3b8ceb67ed5924f5b87c88f17d80d27911c/68747470733a2f2f706f7365722e707567782e6f72672f346d7974682f6170692f762f737461626c65)](https://packagist.org/packages/4myth/api)[![License](https://camo.githubusercontent.com/55bda3bb280b0033a4b8d9d78bcffc9117ed38efbdfa78262aa1a0502d89c35f/68747470733a2f2f706f7365722e707567782e6f72672f346d7974682f6170692f6c6963656e7365)](https://packagist.org/packages/4myth/api)[![Total Downloads](https://camo.githubusercontent.com/bd3173539991110f6b2a0267fdac26a0f877908e5da069eed58f8ec08cf2f97c/68747470733a2f2f706f7365722e707567782e6f72672f346d7974682f6170692f646f776e6c6f616473)](https://packagist.org/packages/4myth/api)

#### For Laravel 5.5 and higher

[](#for-laravel-55-and-higher)

This package allows you to sync your data with Laravel 5.5 and higher. Contains two sections of manger and clint

### Package Installation

[](#package-installation)

Require this package in your composer.json and update composer.

```
composer require 4myth/api
```

### Laravel

[](#laravel)

**Laravel 5.5** uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider/Facade.

You can use the Alias for shorter code.

```
use Myth\Api;

Api::name();
```

Finally you can publish the package:

```
php artisan vendor:publish --tag=myth-api
```

### Getting Started

[](#getting-started)

1- Manager Side
---------------

[](#1--manager-side)

- ### Config file:

    [](#config-file)

    The settings you need to setup of connection with your clients. your **`name`** and your **`clients`**.

```
"name"    => "manager",
"clients" => [
      # Client name
      "client-name" => [
          "secret"   => "secret",
          "base_uri" => "http://127.0.0.1/api/v1",
          "models"   => [
              App\User::class => [
                  "uri"         => "user",
                  "transformer" => App\UserApiTransformer::class,
              ],
          ],
          "options"  => [
              "http" => [],
          ],
      ],
  ],
]

```

Example multiple clients:

```
[
    "client-1" => [],
    "client-2" => [],
];
```

Example multiple models with clients:

```
[
    "client-1" => [
        "models" => [
            App\User::class => [],
            Some\Name\SomeModel::class => [],
        ],
    ]
];
```

#### Client config:

[](#client-config)

The `key` of client array must be the client name in your application.

All options **array keys**: `secret`,`base_uri`,`options`,`models`

1. `secret`: Client's authentication secret, which you can obtain from your client.
2. `base_uri`: Client api url. Example: `http://127.0.0.1/api/v1`
3. `options`: Array of your client options. available options: `http`.
    - `http`: GuzzleHttp\\Client options. See:
4. `models`: Array of your models, will be able to `syc` with specific client.
    - `uri`: The `url` or `prefix` of model at your client software.
    - `transformer`: This option will be used automatically when your system sync `send` model data to your client, **you must** make a new transformer for each client's model.

### Setup

[](#setup)

1. Model.
2. Model transformer.

#### Model

[](#model)

Before you begin to use the package you must setup your model by use package `trait`.

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Myth\Api\Traits\HasApiManager;

class User extends Model
{
    use HasApiManager;

    // ....
}
```

#### Model transformer

[](#model-transformer)

first to make a new model **transformer** we have configure in our **config**, we can execute **artisan** command:

```
php artisan myth:make-client-transformer TransformerName
```

then we will find the transformer inside app directory `app\TransformerName.php`

#### Transformer file:

[](#transformer-file)

```
public function body(): array
{
    return [];
}
```

The **body** method must be return an array data that you will send when syncing this model with Client.

Example:

```
public function body(): array
{
    return [ "name" => "MyTh", "password" => 123 ];
}
```

The client will receive in **body** request this array.

### Usage

[](#usage)

#### Access to client:

[](#access-to-client)

to access your client inside your application you can use the `facade` package `Api`

```
use Myth\Api;

$client = Api::client("client-name");
```

#### Access to client models:

[](#access-to-client-models)

```
use Myth\Api;

$client = Api::client("client-name");

/** @var Myth\Api\ClientModelWrapper $model */
$ClientModelWrapper = $client->model(User::class);
$ClientModelWrapper = $client->model(User::find(1));

/** @var \Illuminate\Database\Eloquent\Model $model */
 $model = $ClientModelWrapper->model();
```

#### Send data to client

[](#send-data-to-client)

you can send your data with multiple ways:

```
use Myth\Api;

// facade
$body = [ "name" => "MyTh", "password" => 123 ];
$response = Api::sendToClient("client-name", User::calss, $body);

// ----------------------

// client wrapper
$client = Api::client("client-name");

$user = User::find(123);
$response = $client->sendData($user);
dd($response);

$body = [ "name" => "Name", "password" => "123456789"];
$response = $client->sendData(User::class,$body);
dd($response);

// ----------------------

// by model directly
$user = User::find(2);
$response = $user->sendToClient("client-name");
dd($response);
```

#### Response

[](#response)

The response using class `ResponseInterface` package contains methods you can access easily in your code

1. `request`: \\GuzzleHttp\\Psr7\\Response See:
2. `response`: array client response
3. `client_id`: the unique id at client in database.

#### Client locale storage

[](#client-locale-storage)

```
use Myth\Api;

$data = Api::clientData("client-name", User::class, $sync = true)->get();
$data = Api::clientData("client-name", User::class, $sync = false)->get();
$data = Api::clientData("client-name", User::class, $sync = null)->get();
dd($data);

$client = Api::client('client-name');
$data = $client->model(User::class)->data($sync = true)->get();
$data = $client->model(User::class)->data($sync = false)->get();
$data = $client->model(User::class)->data($sync = null)->get();
dd($data);

$data = User::clientData("client-name", $sync = true)->get();
$data = User::clientData("client-name", $sync = false)->get();
$data = User::clientData("client-name", $sync = null)->get();
dd($data);
```

#### Mark your models

[](#mark-your-models)

set must sync with client

```
use Myth\Api;

$model = Api::syncWithClient("client-name", $client_id = 4, $model = User::find(1));
$model = Api::client("client-name")->syncModel($client_id = 5, $model = User::find(1));
$model = User::find(1)->syncWithClient("client-name", $client_id = 3);
```

set synced with client

```
use Myth\Api;

$model = Api::syncedWithClient("client-name", $client_id = 4, $model = User::find(1));
$model = Api::client("client-name")->syncedModel($client_id = 5, $model = User::find(1));
$model = User::find(1)->syncedWithClient("client-name", $client_id = 3);
```

unsync model with client `Delete relation`

```
use Myth\Api;

$model = Api::unsyncWithClient("client-name", $client_id = 1, $model = User::find(1));
$model = Api::client("client-name")->unsyncModel($client_id = 1, $model = User::find(1));
$model = User::find(1)->unsyncWithClient("client-name", $client_id = 1);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Total

3

Last Release

2224d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

httpapilaravelsyncmyth4myth

### Embed Badge

![Health badge](/badges/4myth-api/health.svg)

```
[![Health](https://phpackages.com/badges/4myth-api/health.svg)](https://phpackages.com/packages/4myth-api)
```

###  Alternatives

[pusher/pusher-http-laravel

\[DEPRECATED\] A Pusher bridge for Laravel

400509.0k3](/packages/pusher-pusher-http-laravel)[lomkit/laravel-rest-api

A package to build quick and robust rest api for the Laravel framework.

59152.2k](/packages/lomkit-laravel-rest-api)[vinelab/http

An http library developed for the laravel framework. aliases itself as HttpClient

59300.2k11](/packages/vinelab-http)[api-platform/laravel

API Platform support for Laravel

59126.4k5](/packages/api-platform-laravel)[laragear/api-manager

Manage multiple REST servers to make requests in few lines and fluently.

161.8k](/packages/laragear-api-manager)

PHPackages © 2026

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