pobble's avatar

Lumen / Laravel Database Connections

Hello peeps.

I decided to muck about with the idea of microservices. So, baby steps, I created a Laravel app and a Lumen app with an API for it to consume.

I'm using Laragon (couldn't get Homestead to behave on my PC at home) so they're both running under Apache and use databases on the same instance of SQL Server.

Something odd is happening!

The Lumen app's database connection is fine. It runs migrations properly and uses Eloquent to grab a collection. If I hit the endpoint in a browser or with Postman it returns exactly what I expect.

But, when using Guzzle from the Laravel app the Lumen app uses the Laravel app's database connection!

I'm flumoxed, Anybody got an ideas about what might be happening here?

Thanks artisans! Pobble

0 likes
3 replies
pobble's avatar

I don't like to bump posts but this has me well and truly beaten. Six hours spent scratching my head and no joy what-so-ever!

Help meeee!

bobbybouwmann's avatar

Not sure what could be happening, do you have an example of the code that you execute?

pobble's avatar

Here we go ...

Laravel .env

DB_HOST=localhost
DB_DATABASE=pobble
DB_USERNAME=pobble
DB_PASSWORD=secret

Lumen .env

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=pobble-locations
DB_USERNAME=pobble-locations
DB_PASSWORD=secret

Laravel Routes

use GuzzleHttp\Client;

Route::get('ms', function() {
    $guzzle = new Client();
    $response = $guzzle->get('http://pobble-locations.dev/v1/all');
    return $response;
});

Lumen routes

use App\Models\Location;

$app->get('v1/all', function() {
    return Location::all();
});

Please or to participate in this conversation.