Reputation: 61
I have an interesting question about Laravel Eloquent usage. I'm writing an admin panel based on Laravel with Nova. It should to send request and receive a response to a rest api. Is there any solution to use my eloquent models as an "api request"?
I'm thinking about if I make the following: User::all()
and after this, in the background the api send a request to the api's "users end-point", and I get back a collection ?
It may call this some "api driver" instead of mysql driver, or some adapter for this, but I don't know where I should to looking for, or what I have to do.
It would be nice if I can use this because, I can use the all of eloquent features on the response json.
Upvotes: 3
Views: 1489
Reputation: 912
Sushi is an eloquent array driver that works with data arrays instead of databases. I used guzzle to load the data from api into data arrays and use sushi to funnel into an Eloquent model.
https://github.com/calebporzio/sushi
Upvotes: 1
Reputation: 66
There is the "Laravel API Model Driver" which can be found here:
https://github.com/nazarii-kretovych/laravel-api-model-driver
It is also documented at packagist and does what you are looking for. Give the author a star on github since that repo seams to be a really usefull tool missing in the laravel core but that package is hard to find.
There is also another solution you could base your work on, but you would have to fork the git repo and rewrite the code to match your needs:
https://github.com/bahung1221/ApiDriver
In 2014 Tylor Otwell himselve stated that the core team is not planning that feature but one "could give it a shot".
Upvotes: 0