I have two laravel projects, one have an API(laravel_1) and the other consumes it(laravel_2). I can call the api on Postman without problem or consume api on laravel_1 using guzzle call, but when I do the same on laravel_2 it throws error of databases if I try to call some eloquent method like Articles::all(); for example, so I did some tests and seems like laravel_2 try to uses his .env when calling laravel_1.
If I call the laravel_1 api from postman it returns his app name correct "Laravel_1" but if I call it from laravel_2 it's says "Laravel_2" it takes his own app.env name instead of laravel_1 how is that? Also it's the same when I try to call a database
Here is laravel_1 api code:
web.php:
Route::post('/housingAPI/getEventOffers', 'HousingApiController@getEventOffers')->name("housingApi.getEventOffers");
HousingApiController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HousingApiController extends Controller
{
public function getEventOffers(Request $request)
{
//todo code here with requests
return config('app.name');
}
}
and here is laravel_2 config:
web.php
Route::get('/test', 'HousingInfoController@index')
HousingInfoController.php
<?php
namespace App\Http\Controllers\frontend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class HousingInfoController extends Controller
{
public function test()
{
//Ofertas de eventos
$eventOffers = $this->getAllEventOffersApiCall("H", 1, 416, "esp", '');
}
private function getAllEventOffersApiCall($type, $zoneId, $hotelId, $lang, $moda, $ajax = false)
{
$form_params = [
'type' => $type,
'zoneId' => $zoneId,
'hotelId' => $hotelId,
'lang' => $lang,
'moda' => $moda,
'ajax' => $ajax
];
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'http://laravel-api.test/housingAPI/getEventOffers', ['form_params' => $form_params]);
$body = $response->getBody();
dd($body->getContents());
return json_decode($body->getContents(), true);
}
}