0

I have two projects in Laravel .Let's consider Project A and Project B and their databases respectively pA & pB. At one point i needed a communication channel between both projects so i wrote a api in Project A so that Project B could access data from that api . I tested my api in postman it worked fine . so spoof the same Curl Request from Project B . The result was unexpected on further debugging i found that on Curl request Project A started using database of project B . It doesn't make any sense both projects are stand alone on their own . For further investigation i changed the api code of project B to just print database name and now it was confirm that same code was showing different results When i requested from postman it pA as expected but from Curl request it resulted in pB

here's my api method in Project A

 public function nextmlaNotify(){
        dd(\DB::getDatabaseName(););    

    }

and this how i am requesting data from Project B

public function testing(){
   $ch = curl_init();
            $body=['name'=>'Prince'];
            curl_setopt($ch, CURLOPT_URL,"projectA/emsapi/nextmla/notifier");
            curl_setopt($ch, CURLOPT_POST, 1);

            curl_setopt($ch, CURLOPT_POSTFIELDS, 
                     http_build_query($body));

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $output = curl_exec ($ch);
            curl_close ($ch);
            return $output;

        }

I have no clue what i am doing wrong i tried everything

Prince Arora
  • 354
  • 1
  • 6
  • 20
  • Change the name of the connections in **config/database.php** then set it as a new default connection `'default' => 'new_connection_name'`. Another solution would be adding new connection and using it like `DB::connection('extra_connection') ->table('table_name') ->where('RefDate', '<', $date_start->toDateString())->get()` – berkay kılıç Jun 12 '18 at 11:13
  • for that i have to change every model's connection property and i tried extra connection it works fine but still the problem is connection details are static in database.php i tried to make it dynamically pickable from .env file and same problem started with extra connection – Prince Arora Jun 12 '18 at 11:16
  • Is this on a same server? If yes then this is a duplicate of https://stackoverflow.com/a/42081373/1564365 You can mitigate this using `artisan config:cache`. – Kyslik Jun 12 '18 at 12:05

0 Answers0