title: Storing parts of API data to database
body: <p><strong>Goal:</strong> I want to retrieve all the upcoming soccer matches for the upcoming week from a RESTful API. Once I get this data I would like to store the result in my database. </p>
  
  <p>What I want to store: <code>'id', 'homeTeam', 'awayTeam', 'utcDate'</code>. I want to do this for every match, so all the arrays in <code>'matches'</code></p>
  
  <p>How my API result looks:</p>
  
  <pre><code>array:4 [▼
  "count" =&gt; 10
  "filters" =&gt; array:1 [▶]
  "competition" =&gt; array:6 [▶]
  "matches" =&gt; array:10 [▼
  0 =&gt; array:12 [▼
    "id" =&gt; 233107
    "season" =&gt; array:4 [▶]
    "utcDate" =&gt; "2018-10-20T11:30:00Z"
    "status" =&gt; "SCHEDULED"
    "matchday" =&gt; 9
    "stage" =&gt; "REGULAR_SEASON"
    "group" =&gt; "Regular Season"
    "lastUpdated" =&gt; "2018-10-07T19:02:21Z"
    "homeTeam" =&gt; array:2 [▼
      "id" =&gt; 61
      "name" =&gt; "Chelsea FC"
    ]
    "awayTeam" =&gt; array:2 [▼
      "id" =&gt; 66
      "name" =&gt; "Manchester United FC"
    ]
    "score" =&gt; array:6 [▶]
    "referees" =&gt; []
  ]
  1 =&gt; array:12 [▶]
  2 =&gt; array:12 [▶]
  3 =&gt; array:12 [▶]
  4 =&gt; array:12 [▶]
  5 =&gt; array:12 [▶]
  6 =&gt; array:12 [▶]
  7 =&gt; array:12 [▶]
  8 =&gt; array:12 [▶]
  9 =&gt; array:12 [▶]
   ]
  ]
  </code></pre>
  
  <p>I use Guzzle for doing this API request:</p>
  
  <pre><code>class GuzzleController extends Controller {
      public function getMatches() {
          $client = new Client();
          $uri = 'http://api.football-data.org/v2/competitions/PL/matches/?matchday=9&amp;season=2018&amp;matches';
          $header = ['headers' =&gt; ['X-Auth-Token' =&gt; 'My-Token']];
          $res = $client-&gt;get($uri, $header);
          $array = json_decode($res-&gt;getBody()-&gt;getContents(), true);
          dd($array);
      }
  }
  </code></pre>
  
  <p>I created a model 'Match' and added a migration:</p>
  
  <pre><code>class Match extends Model {
      // What code here?
  }
  </code></pre>
  
  <p>The migration:</p>
  
  <pre><code>public function up() {
      Schema::create('matches', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;timestamps();
          $table-&gt;integer('match_id');
          $table-&gt;string('homeTeam');
          $table-&gt;string('awayTeam');
      });
  }
  </code></pre>
  
  <p>Any tips on how to store this data to my database on the match model?</p>