title: Testing API call in laravel controller/view
body: <p>I'm testing an API call that I have working in Postman and other interfaces built over the API, but I'm trying to actually get my return values within my laravel site.</p>
  
  <p>Should be simple enough, I made a very bare service file that uses guzzle to get to the API url, and I have a function in there for logging in using a test email, password and client ID (all of which work in the api interface such as Postman)</p>
  
  <p>I'm calling the class and function inside my authController and then returning the function call in the view, then dumping that inside the view.</p>
  
  <p>However, currently I'm getting null on my page dump.</p>
  
  <p>Is there something I'm missing here, possibly in my service file. I don't think there should be anything passed here, but maybe I'm overlooking something more obvious.</p>
  
  <p>Authorize.php</p>
  
  <pre><code>&lt;?php
  namespace App\Services\restAPI;
  
  use Illuminate\Support\Facades\Auth;
  use GuzzleHttp\Exception\ClientException;
  use GuzzleHttp\Exception\ServerException;
  
  
  use Session;
  use Exception;
  
  class AuthService
  {
  
      protected $baseurl;
      protected $guzzleClient;
  
      public function  __construct() {
          $this-&gt;baseurl = config('http://ip.address');
          $this-&gt;baseurl = rtrim($this-&gt;baseurl, '/') . '/';  // ensure trailing slash
  
          $this-&gt;guzzleClient = new \GuzzleHttp\Client(
              ['verify'   =&gt; config('app.ca_pem_file'),
               'headers'  =&gt; [
                      'Event-ID' =&gt; ACCESS_EVENT_ID
                  ],
               'base_uri' =&gt; $this-&gt;baseurl
              ]
          );
      }
  
      public function loginGetToken(){
          $password = "password";
          $email = "test@thisAPI.com";
          $client_id = "0";
  
          $payload = (object)[
              'password'=&gt;(string)$password,
              'email'=&gt;(string)$email
          ];
  
          $retval = $this-&gt;post('login/?client_id='.$client_id,$payload);
  
          return $retval;
      }
  
      private function post($endpoint,$payload){
  
          $result = $this-&gt;guzzleClient-&gt;request('POST', $endpoint, ['json'=&gt;$payload]);
          $body = $result-&gt;getBody();
          return  json_decode($body);
      }
  }
  </code></pre>
  
  <p>AuthController.php</p>
  
  <pre><code>use Redirect;
  use Illuminate\Http\Request;
  use App\Services\restAPI\AuthService;
  
  class AuthController extends Controller
  {
      public function login(Request $request)
      {
          $authService = new AuthService();
          $login = $authService-&gt;loginGetToken();
  
           return redirect(route('auth.login'))
              -&gt;with('login', $login)
      }
  </code></pre>
  
  <p>login.blade.php</p>
  
  <pre><code>&lt;?php
  
      dd($login);
  
  ?&gt;
  </code></pre>