title: Set the Authorization Bearer header in Guzzle HTTP client After Login Action - Laravel
body: <p>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.</p>
  <p>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.</p>
  <p>Can I do that using Guzzle?</p>
  <p>This is my function for login</p>
  <pre><code>public function login(Request $request)
  {
      $client = new Client();
      $url = &quot;http://localhost:8002/login&quot;;
  
      $request = $client-&gt;post($url, [
          'headers'=&gt; ['Content-Type' =&gt; 'application/json'],
          'body' =&gt; json_encode([
              'email' =&gt; $request-&gt;email,
              'password' =&gt; $request-&gt;password,
          ])
      
      ]);
  
      $response = json_decode($request-&gt;getBody());
      $token = $response-&gt;result-&gt;token; //I have got the token
      
  
  }
  </code></pre>