Download the PHP package rustyphp/microservice-crud without Composer
On this page you can find all versions of the php package rustyphp/microservice-crud. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package microservice-crud
Lush Digital - CRUD
A CRUD convenience layer for microservices built in Lumen.
Description
This package is intended to provide a convenient layer on top of Lumen to streamline the process of developing a RESTful CRUD microservice. It reduces the repetitive nature of writing controllers, models and CRUD logic over and over again.
Package Contents
- An abstract controller which can be extended for quick RESTful CRUD logic.
- Cache clearing observer to ensure your data always appears as up-to-date as possible.
Installation
Install the package as normal:
The package requires that the following changes are made to the Lumen config in bootstrap/app.php
Usage
To create a new CRUD resource first extend your model from \LushDigital\MicroServiceModelUtils\Models\MicroServiceBaseModel
.
The model must also implement the LushDigital\MicroServiceCrud\Models\CrudModelInterface
interface.
Next you need to create a controller which extends from \LushDigital\MicroServiceCrud\Http\Controllers\CrudController
Finally if you are using caching you need to register the Crud observer against your model. Do this by editing the
existing app/Providers/AppServiceProvider.php
class (or add a new service provider) like so:
Make sure that your service provider is added (or uncommented) in bootstrap/app.php
:
Model
Note that above the model is called Example
and the controller is called ExamplesController
. This follows the
plural pattern you're used to with Laravel. Basically the controller name needs to be the plural version of the model
plus 'Controller'.
This can be changed by overriding the $modelBaseClass
attribute in the controller:
Model Namespace
The CRUD controller assumes the model exists in the App\Models
namespace (e.g. App\Controllers\ExamplesController => App\Models\Example
).
This can be changed by overriding the $modelNamespace
attribute:
Cache Attributes
The package provides support for caching data based on any attribute of a model. By default the package will cache data
using the id attribute only. This works using cache keys, so for an instance of the Example
model with id 1 the
following cache keys will be set on read and cleared on update/delete:
Note the
:index
cache key is always used for the indexing endpoint listing all model instances.
To cache based on other attributes just override the $attributeCacheKeys
attribute in your model:
So in this cache Example (ID: 1) with a name of 'test' would have a cache key of
examples:name:test
Routing
Once your controller and model are set up you need to configure routes. The package provides logic for the standard REST endpoints (GET, POST, PUT, DELETE). You can use as many or as few as you like, an example of all routes would be:
All versions of microservice-crud with dependencies
biliboobrian/microservice-core Version ~1.0
biliboobrian/microservice-model-utils Version ~1.0