Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luis199230/eloquent-for-api
This package allow use models and relationships using resources of API how to entities.
https://github.com/luis199230/eloquent-for-api
eloquent eloquent-api laravel microservices
Last synced: 21 days ago
JSON representation
This package allow use models and relationships using resources of API how to entities.
- Host: GitHub
- URL: https://github.com/luis199230/eloquent-for-api
- Owner: luis199230
- License: gpl-3.0
- Created: 2019-12-20T07:07:56.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-08T23:39:56.000Z (about 5 years ago)
- Last Synced: 2024-11-13T00:34:16.905Z (3 months ago)
- Topics: eloquent, eloquent-api, laravel, microservices
- Language: PHP
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Eloquent-for-API
![Packagist](https://img.shields.io/packagist/dm/luis199230/eloquent-for-api?style=plastic)
![GitHub stars](https://img.shields.io/github/stars/luis199230/eloquent-for-api?style=plastic)This package allow use models and relationships using resources of API how to entities.
## Installation
```sh
composer require madeweb/eloquent-api
```Generate model wrapper for call to api
```sh
php artisan make:model-api Model --api=API\\NameOfAPI
```Generate model wrapper for authentication with passport
```sh
php artisan make:model-api Model --api=API\\NameOfAPI --auth
```## Configure
#### Use fillable in models
Is very important setup the fillable because this variable allow recognize the fields will have your model.```sh
protected $fillable = ['uuid', 'name', 'last_name', 'phone', 'document_type', 'document_number',
'birthdate', 'civil_status', 'gender', 'address_uuid', 'user_uuid'];
```#### Relationships
For prepare relations between model is required use this syntax. For example for the person model the order of parameters is class belongs, key for identify relationship, common key or field in both models, and method of API for connecting.```sh
public function user()
{
return $this->relationship(User::class, 'user', $this->user_uuid, 'find');
}
```#### Methods Basics
How it is an api, it is necessary to define own functions to call basic methods that exist in eloquent. For example, in this function, the showPerson method must exist in the API.```sh
public function find($uuid)
{
$response = $this->connection->showPerson($uuid);
return $this->prepareResponse($response);
}
```