Download the PHP package robertogallea/eloquent-api without Composer
On this page you can find all versions of the php package robertogallea/eloquent-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download robertogallea/eloquent-api
More information about robertogallea/eloquent-api
Files in robertogallea/eloquent-api
Package eloquent-api
Short Description Eloquent models backed by Rest API
License MIT
Informations about the package eloquent-api
Eloquent Models for json APIs
A package that lets you lay Eloquent on top of a json web API.
This package provides an Eloquent model that sits on top of a json web API endpoint.
When you use this package, an initial invocation of the model will make one or more requests to an HTTP endpoint, data are read and converted in an array of rows. Each row is stored as a record in a table inside a file-based sqlite database. Subsequent invocations of the model use that sqlite database so changes underlying data won't be reflected in the database. However, there are two ways that you can invalidate the sqlite cache and cause it to be recreated:
-
You can call the
invalidateCache()
method on the model with something likeYourApiModel::first()->invalidateCache()
- By sending a request to a route provided by this package that deletes the sqlite database forcing a fresh load the next time the model is used.
Installation
Usage
Consider the following JSON response, provided by the endpoint https://ghibliapi.herokuapp.com/films
We want to lay an Eloquent model on top of it.
Step 1 - Enter the full path to the directory where you want to create the model file (defaults to app_path()
):
Step 2 - Enter the name you want to use for your model class:
Step 3 - Paste the endpoint of your resource:
Step 4 - If your data is wrapped in a particular field, type its name:
Step 5 - If your resource is paginated, type the json field containing the url of the next page:
Step 6 - Confirm that the path and full classname look right:
The Resulting Model Class
Dealing with wrapped resources
If your resource data is wrapped into a particular json key, you need to tell your model, what this key is, by setting
the $dataField
model attribute. For example
Dealing with paginated data
If your endpoint provides paginated data, the package support multiple page fetching. In this case all you need to do,
is setting the $nextPageField
attribute as a string containing the name of the json field containing the next page
link, for example
This model can do your basic Eloquent model stuff because it really is an Eloquent model. Though it's currently limited to read / list methods. Update and insert don't currently work.
Issues, Questions and Pull Requests
You can report issues and ask questions in the issues section. Please start your issue with ISSUE: and your question with QUESTION:
If you have a question, check the closed issues first. Over time, I've been able to answer quite a few.
To submit a Pull Request, please fork this repository, create a new branch and commit your new/updated code in there. Then open a Pull Request from your new branch. Refer to this guide for more info.
All versions of eloquent-api with dependencies
calebporzio/sushi Version ^2.0
guzzlehttp/guzzle Version ^6.5|^7
ext-json Version *