I'm currently working on a laravel project to make a request to the API. Every request to an endpoint requires a token in the header.
I created a function for login, when login is successful I want to put a token in the header for each request to the endpoint.
Can I do that using Guzzle?
This is my function for login
public function login(Request $request)
{
$client = new Client();
$url = "http://localhost:8002/login";
$request = $client->post($url, [
'headers'=> ['Content-Type' => 'application/json'],
'body' => json_encode([
'email' => $request->email,
'password' => $request->password,
])
]);
$response = json_decode($request->getBody());
$token = $response->result->token; //I have got the token
}