Download the PHP package windawake/laravelremodel without Composer
On this page you can find all versions of the php package windawake/laravelremodel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download windawake/laravelremodel
More information about windawake/laravelremodel
Files in windawake/laravelremodel
Package laravelremodel
Short Description Create remote driver to convert remote api request into laravel model.
License MIT
Informations about the package laravelremodel
laravel remote model
Create remote driver to convert remote api request into laravel model.
In order to discuss technology with me, you can add me to wechat.
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.
Then execute command to create the SQLite database file test.db
Add the configuration of sqlite and adds testsuite of Remote in phpunit.xml.
Finally, run the test command ./vendor/bin/phpunit --testsuit=Remote
The running results are shown below, 18 orm examples have passed in the test.
features
- The app backend code does not need to be refactored, and it is gradually realizing the progressive service of API interface.
- Support lazy loading, avoiding 1+n query api.
- Supports join tables, union tables, native SQL queries, aggregate queries, sub-queries, etc. Almost all laravel orm features can be used.
- The laravel service container writing method is used, so the query compiler and distributed transaction methods can be customized. (Distributed transaction component is recommended).
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.
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
Create a new ProductRemote class that inherits the RemoteModel class.
The above is an example of querying getHandle. By default, 5 methods are provided: getHandle, updateHandle, insertGetIdHandle, deleteHandle and existsHandle. After inheriting the RemoteModel class, without defining these methods such as getHandle, it will use the db drive by default, just like the normal Model class.
model method | similar to mysql syntax | purpose |
---|---|---|
getHandle | select | Query list, query details, query aggregation operations (count, max, etc.) |
updateHandle | update | Update record |
insertGetIdHandle | insert | Insert record |
deleteHandle | delete | Delete record |
existsHandle | select | Determine whether it exists |