title: Laravel - Save Guzzle JSON response to Database
body: <p>I am using Guzzle to access an external API:</p>
  
  <pre><code>$api = new Client([
      'base_uri' =&gt; 'https://www.space-track.org',
      'cookies' =&gt; true, 
  ]);
  $api-&gt;post('ajaxauth/login', [
       'form_params' =&gt; [
           'identity' =&gt; 'myidentity', 
           'password' =&gt; 'mypassword', 
        ],
  ]);
  $response = $api-&gt;get('basicspacedata/query/class/boxscore/format/json');
  return json_decode($response-&gt;getBody()-&gt;getContents());
  $api-&gt;get('ajaxauth/logout');
  dd($boxscore);
  </code></pre>
  
  <p>With this I am able to access the API and display the JSON file on my webpage. Instead of doing this, what I want to do is to save the JSON result into my database and then display it from my own database.</p>
  
  <p>I am able to seed a local JSON file, but I am unable to save the Guzzle result. </p>
  
  <p>Is there anyway to save a Guzzle response JSON file into my database?</p>
  
  <p><strong>EDIT:</strong>
  Here is the model and migration for the database:</p>
  
  <p><em>Migration</em></p>
  
  <pre><code> Schema::create('operators', function (Blueprint $table) {
       $table-&gt;increments('id');
       $table-&gt;string('COUNTRY');
       $table-&gt;string('SPADOC_CD');
       $table-&gt;string('ORBITAL_TBA');
       $table-&gt;string('ORBITAL_PAYLOAD_COUNT');
       $table-&gt;string('ORBITAL_ROCKET_BODY_COUNT');
       $table-&gt;string('ORBITAL_DEBRIS_COUNT');
       $table-&gt;string('ORBITAL_TOTAL_COUNT');
       $table-&gt;string('DECAYED_PAYLOAD_COUNT');
       $table-&gt;string('DECAYED_ROCKET_BODY_COUNT');
       $table-&gt;string('DECAYED_DEBRIS_COUNT');
       $table-&gt;string('DECAYED_TOTAL_COUNT');
       $table-&gt;string('COUNTRY_TOTAL');
   });
  </code></pre>
  
  <p><em>Model</em></p>
  
  <pre><code> protected $fillable = [
      'COUNTRY',
      'SPADOC_CD',
      'ORBITAL_TBA',
      'ORBITAL_PAYLOAD_COUNT',
      'ORBITAL_ROCKET_BODY_COUNT',
      'ORBITAL_DEBRIS_COUNT',
      'ORBITAL_TOTAL_COUNT',
      'DECAYED_PAYLOAD_COUNT',
      'DECAYED_ROCKET_BODY_COUNT',
      'DECAYED_DEBRIS_COUNT',
      'DECAYED_TOTAL_COUNT',
      'COUNTRY_TOTAL'
  ];
  </code></pre>
  
  <p><strong>EDIT 2:</strong>
  I have received some help in regards to this question. I am able to create a model that mirrors the database:</p>
  
  <pre><code>$api = new Client([
  'base_uri' =&gt; 'https://www.space-track.org',
  'cookies' =&gt; true, 
   ]); $api-&gt;post('ajaxauth/login', [
        'form_params' =&gt; [
           'identity' =&gt; 'myidentity', 
           'password' =&gt; 'mypassword', 
       ],
   ]);
   $response = $api-get('basicspacedata/query/class/boxscore/format/json');
    $mydata = json_decode($response-&gt;getBody()-&gt;getContents());
    $object = new Object();
    $object-&gt;COUNTRY = $mydata-&gt;COUNTRY;
    $object-&gt;SPADOC_CD = $mydata-&gt;SPADOC_CD
    $object-&gt;save();
  return redirect('your/url',compact('object'));
  </code></pre>
  
  <p>This pulls the data from the database, but does not save it. It allows me to access the saved variable.</p>
  
  <p>What I need to do is to somehow save the variable into my 'satellite' database.</p>
  
  <p>TL;DR:  I simply want to save the data fetched from the API to my database</p>