Using Laravel with microservices: Is it possible to use eloquent without a database?

1 answer

We're using a microservice architecture. There are 2 sets of data for the laravel service:

  • The database that houses the admins.
  • And all the other data that admins can access, which comes via GRPC calls to other services.

I want something like eloquent (maybe API Resource?) for structuring data/relationships, but instead of making Database-queries to load data, it needs to make GRPC calls to other services. I was thinking of making a custom class that extends off of eloquent and overloading the protected functions that make calls to the database, but that sounds like a recipe for a bad time. If anybody has experience doing what I'm describing, what direction did you go? What worked? what didn't?

All answers to this question, which has the identifier 61068058

The best answer:

So, I ended up not using eloquent at all. I continued using the protoc set up as the documentation explains. But I used Route-binding to enable type-hinting in controllers:

<?php  namespace App\Providers;  use OurNamespace\GrpcClient; use Illuminate\Support\Facades\Route; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use OurNamespace\Customer; use OurNamespace\CustomerIdInput;  class RouteServiceProvider extends ServiceProvider {     /**      * This namespace is applied to your controller routes.      *      * In addition, it is set as the URL generator's root namespace.      *      * @var string      */     protected $namespace = 'App\Http\Controllers';      /**      * Define your route model bindings, pattern filters, etc.      *      * @return void      */     public function boot()     {         //          parent::boot();         Route::bind('customer', function ($customerId) {             $grpcClient = app(GrpcClient::class);             $customerIdInput = new CustomerIdInput();             $customerIdInput->setCustomerId($customerId);             list($customer, $status) = $grpcClient->GetCustomerDetails($customerIdInput)->wait();             if ($status->code != 0) {                 error_log('ERROR - ' . print_r($status, 1));                 return redirect()->back()->withErrors(['There was an error retrieving that customer', $status->details]);             }             return $customer;         }); 

The GrpcClient is coming from the AppServiceProvider. This way if we want to make a query we don't have to manually instantiate it.

<?php  namespace App\Providers;  use Illuminate\Support\ServiceProvider; use OurNamespace\GrpcClient; use Grpc\ChannelCredentials;  class AppServiceProvider extends ServiceProvider {     /**      * Register any application services.      *      * @return void      */     public function register()     {         $this->app->singleton('OurNamespace\GrpcClient', function ($app) {             return new GrpcClient(env('GRPC_HOST'), [                 'credentials' => ChannelCredentials::createInsecure(),             ]);         });  

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type is referenced as an interface from”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data