use GuzzleHttpClient;
use GuzzleHttpCookieCookieJar;
use IlluminateSupportFacadesHttp;
....
// Get the token generated when you are logged
public function getToken(){
$response = Http::withHeaders([
'login' => 'login',
'password' => 'password'
])->post('/urlOfConnection');
return $response->cookies()->getCookieByName('cookieName');
}
// Get data from api with cookie
public function getDataFromApi(){
$jwt = $this->getToken();
$cookieJar = CookieJar::fromArray([
$jwt->getName() => $jwt->getValue()
], $jwt->getDomain());
$req = new Client();
$res = $req->request('GET', '/getDataFromApi',
['cookies' => $cookieJar]);
return $res->getBody();
}