PHPackages                             windawake/laravelremodel - 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. [API Development](/categories/api)
4. /
5. windawake/laravelremodel

ActiveLibrary[API Development](/categories/api)

windawake/laravelremodel
========================

Create remote driver to convert remote api request into laravel model.

v1.0.1(4y ago)17332MITPHPPHP ^7.0

Since Oct 13Pushed 4y ago2 watchersCompare

[ Source](https://github.com/windawake/laravelremodel)[ Packagist](https://packagist.org/packages/windawake/laravelremodel)[ RSS](/packages/windawake-laravelremodel/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)DependenciesVersions (2)Used By (0)

laravel remote model
====================

[](#laravel-remote-model)

[![中文](https://camo.githubusercontent.com/03bfbb677deb58533f858b4c2e1751b611bff76be5095ab5a60db7ad20e97c27/68747470733a2f2f736869656c64732e696f2f7374617469632f76313f6c6162656c3d7a682d636e266d6573736167653d25453425423825414425453625393625383726636f6c6f723d726564)](https://github.com/windawake/laravelremodel/blob/master/README_zh-CN.md)[![日本語](https://camo.githubusercontent.com/cc54da99c24b65a38f912382c92fdb70844e8ca075ed04cea088d6aa85c6100c/68747470733a2f2f736869656c64732e696f2f7374617469632f76313f6c6162656c3d6a612d6a70266d6573736167653d25453625393725413525453625394325414325453825414125394526636f6c6f723d626c7565)](https://github.com/windawake/laravelremodel/blob/master/README_ja.md)

Create remote driver to convert remote api request into laravel model.

[![](https://github.com/windawake/notepad/raw/master/images/webchat01.jpg)](https://github.com/windawake/notepad/blob/master/images/webchat01.jpg)

In order to discuss technology with me, you can add me to wechat.

overview
--------

[](#overview)

Install the version between laravel5.5-laravel8, and then install the quick microservice package.

> composer require windawake/laravelremodel dev-master

First execute the command `php artisan laravelremodel:example-models` to copy the three files OrderDetailRemote.php, OrderRemote.php, and ProductRemote.php (under the `./vendor/windawake/laravelremodel/examples/Models directory`) into the `app` folder.

```
├── app
│   ├── Console
│   │   └── Kernel.php
│   ├── Exceptions
│   │   └── Handler.php
│   ├── Http
│   │   ├── Controllers
│   │   ├── Kernel.php
│   │   └── Middleware
│   ├── Models
│   │   ├── OrderDetailRemote.php
│   │   ├── OrderRemote.php
│   │   └── ProductRemote.php
```

Then execute command to create the SQLite database file test.db

```
php ./vendor/windawake/laravelremodel/examples/sqlite/build.php
```

Add the configuration of sqlite and adds testsuite of Remote in phpunit.xml.

```

            ./tests/Unit

            ./tests/Feature

            	./vendor/windawake/laravelremodel/tests

            ./app

```

Finally, run the test command `./vendor/bin/phpunit --testsuit=Remote`The running results are shown below, 18 orm examples have passed in the test.

```
root@DESKTOP-VQOELJ5:/web/linux/php/laravel/laravel58# ./vendor/bin/phpunit --testsuit=Remote
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

..................                                                18 / 18 (100%)

Time: 208 ms, Memory: 20.00 MB

OK (18 tests, 21 assertions)
```

features
--------

[](#features)

1. The app backend code does not need to be refactored, and it is gradually realizing the progressive service of API interface.
2. Support lazy loading, avoiding 1+n query api.
3. Supports join tables, union tables, native SQL queries, aggregate queries, sub-queries, etc. Almost all laravel orm features can be used.
4. The laravel service container writing method is used, so the query compiler and distributed transaction methods can be customized. ([Distributed transaction component is recommended](https://github.com/windawake/laravel-reset-transaction)).

principle
---------

[](#principle)

The api interface of the remote basic service is encapsulated into an ORM. The my app model is just a virtual model, which is a mirror image of remote basic service model. [![](https://github.com/windawake/notepad/raw/master/images/file01.jpg)](https://github.com/windawake/notepad/blob/master/images/file01.jpg)For example, the purple ProductModel is a mirror image, but OrderLogic uses it almost the same as the white ProductModel. What are the benefits of doing this? All the features of the laravel model can be reused. Because many packages now do a lot of new functions for the model, it is a pity not to use them.

how to use
----------

[](#how-to-use)

Create a new ProductRemote class that inherits the RemoteModel class.

```
