Download the PHP package crucialdigital/metamorph without Composer
On this page you can find all versions of the php package crucialdigital/metamorph. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download crucialdigital/metamorph
More information about crucialdigital/metamorph
Files in crucialdigital/metamorph
Package metamorph
Short Description Package of data models managements
License MIT
Homepage https://github.com/crucialdigital/metamorph
Informations about the package metamorph
Crucial Digital Metamorph
Metamorph is a Laravel package that implements a data model system based on mongodb. This package provides a powerful system for managing dynamically models for api development.
Before going any further, consider that this package is intended for API development with Laravel and Mongodb
Table of contents
- Installation
- Usage
- Creating Model, Repository and data model
- Configure data model into metamorph config file
- Run your data models
- Make API requests
- Advanced
- Global Middleware
- Model Middleware
- Policies
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Installation
You can install the package via composer:
You must now publish the config file with:
Usage
Creating Model Repository and data model
Create your data model files with artisan command:
This command will create three files:
- Eloquent model file
Is Laravel Eloquent model extends from CrucialDigital\Metamorph\BaseModel.php
class.
You are free to create your model with Laravel syntax
and extends CrucialDigital\Metamorph\BaseModel.php
. Consider implement label()
and search()
method responsible
respectively for labeling form resource and define field on witch query with default search term
- Model repository file
Is the repository class responsible for creating the model query builder. You can also create repositories with artisan command
- Data model form file
The json file describes the form that handles the model with all its inputs. The json file structure looks like:
where required fields are entity and inputs.
Each entry of inputs must have at least:
* field: The input field
* name: The label of the input
* type: The input type in list below
* text
* number
* tel
* email
* date
* datetime
* radio
* boolean
* select
* textarea
* url
* selectresource
* resource
* geopoint
For input of type select, options is required and is an array of object with label and value
For input of type selectresource and resource, entity filed is required. The entity must be unique for the model around your application
Other field are :
- required: boolean
- hidden: boolean
- readOnly: boolean
- rules: string (Laravel request rules pipe separated)
- description: string
- placeholder: string
- min: int
- max: int
- unique: boolean
- filters: See table below
You are free to add any other field to the input that you can use in your frontend application
Configure data model into metamorph config file
To configure how metamorph maps model with repository, data model form, controller and routes, you have to indicate in metamorph config file in models and repositories sections respectively the Eloquent model and model repository.
Example :
Run your data models
After creating your data models in .json files, you have to persist into your database with artisan command.
This artisan command persists data models into the database. Every time you
modify .json file in database\models
, update data with this command. You can specify the name of the .json file with --name
parameter
Consider configuring the mongodb database connection before.
Make API requests
Metamorph provides various endpoint de Create, Read, Update en Delete. Available endpoint are :
Methods | Endpoints | Description | Parameters |
---|---|---|---|
POST | api/metamorph/exports/{entity}/{form} | Export data with selected form | entity : mapped model entityform : selected data form |
GET, HEAD | api/metamorph/form-data | ||
POST | api/metamorph/form-data | ||
GET,HEAD | api/metamorph/form-data/{form_datum} | ||
PUT,PATCH | api/metamorph/form-data/{form_datum} | ||
DELETE | api/metamorph/form-data/{form_datum} | ||
POST | api/metamorph/form-inputs | ||
GET,HEAD | api/metamorph/form-inputs/{form_input} | ||
PUT,PATCH | api/metamorph/form-inputs/{form_input} | ||
DELETE | api/metamorph/form-inputs/{form_input} | ||
POST | api/metamorph/form/{entity} | ||
GET,HEAD | api/metamorph/forms | ||
POST | api/metamorph/forms | ||
GET,HEAD | api/metamorph/forms/{form} | ||
PUT,PATCH | api/metamorph/forms/{form} | ||
DELETE | api/metamorph/forms/{form} | ||
POST | api/metamorph/many/search | ||
POST | api/metamorph/master/{entity} | Create model entry | entity : mapped model entity |
GET,HEAD | api/metamorph/master/{entity}/{id} | Get model entry | entity : mapped model entity id : model entity id |
PUT,PATCH | api/metamorph/master/{entity}/{id} | Update model entry | entity : mapped model entity id : model entity id |
DELETE | api/metamorph/master/{entity}/{id} | Delete model entry | entity : mapped model entity id : model entity id |
PATCH | api/metamorph/reject/form-data/{id} | ||
POST | api/metamorph/resources/entities | ||
POST | api/metamorph/resources/entity/ | ||
POST | api/metamorph/search/{entity} | Lists models entries | See table below |
POST | api/metamorph/validate/form-data/{id} |
Model entry list request parameters
Parameter | Description | Parameter type | Value type | Default value |
---|---|---|---|---|
entity |
mapped model entity | string | url part param | |
term |
search term form route search |
string | query param | |
paginate |
whether paginate request or not i.e: 0,1 | string, int | query param | 1 |
per_page |
number of element per page _default | int | query param | 15 |
order_by |
order field | string | query param | _createdat |
order_direction |
order direction of order_by i.e : ASC, DESC |
string | query param | ASC |
randomize |
whether result is randomize Incompatible with paginate | int, string | query param | 0 |
with_trash |
whether result is with trashed entries | int, string | query param | 0 |
only_trash |
whether result is only trashed entries | int, string | query param | 0 |
filters |
filter criteria for the request i.e: Available operator: =, !=, <, >, date, datebefore, dateafter, dateaftereq, datebeforeq, datenot, datebetween, datenotbetween, like, in, notin, between, notbetween, all, exists, elemMatch, size, regexp, type, mod, near, geoWithin, geoIntersects See Mongodb query and projection operators documentation for more operator |
object[ ] | query param | [ ] |
search |
Same as filters | object[ ] | query param | [ ] |
NOTE
field
: value of filters can be nested relation fieldi.e: comments.user._id
coordinator
: one ofand
,or
to indicate using where(...) / orWhere(...)
group
: is used to group filter criteria into sub-query; the value must start with one ofand_
or_
Advanced
Global Middleware
To define global middleware for all metamorph routes, in metamorph config file, config/metamorph.php
fill the middlewares
array with your middlewares
If you are using Laravel Sanctum for authentification, don't forget to add the middleware
auth:sanctum
to avoid trouble with Metamorph authorisation system
Model Middleware
Beyond global middleware you can't define individual middleware for every model route and for each controller action
in metamorph config file, config/metamorph.php
fill the model_middlewares
array with your middlewares
Policies
To authorize model controller action with police authorization,
in metamorph config file, config/metamorph.php
fill the policies
array with the policy actions associate with your models
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Humbert DJAGLO
- Mawaba BOTOSSI
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of metamorph with dependencies
illuminate/contracts Version ^10|^11
illuminate/support Version ^10|^11
intervention/image Version ^2.7
maatwebsite/excel Version ^3.1
mongodb/laravel-mongodb Version ^4.6
psr/simple-cache Version ^2.0|^3.0
spatie/laravel-package-tools Version ^1.13.0