title: Laravel sort array by created_at
body: <p>I need to sort my json array in chronological order by it's created_at timestamps. </p>
  
  <pre><code>  [{
      "id": 1,
      "message": "hello",
      "company_id": 7,
      "investor_id": 35,
      "match_id": 2,
      "created_at": "2015-07-01 12:56:34",
      "updated_at": "2015-07-01 12:56:34"
    }, {
      "id": 2,
      "message": "helloWorld",
      "company_id": 7,
      "investor_id": 35,
      "match_id": 2,
      "created_at": "2015-07-01 12:56:53",
      "updated_at": "2015-07-01 12:56:53"
    }, {
      "id": 3,
      "message": "sup",
      "company_id": 7,
      "investor_id": 35,
      "match_id": 2,
      "created_at": "2015-07-01 13:12:53",
      "updated_at": "2015-07-01 13:12:53"
    }, {
      "id": 4,
      "message": "sup",
      "company_id": 7,
      "investor_id": 35,
      "match_id": 2,
      "created_at": "2015-07-01 13:13:04",
      "updated_at": "2015-07-01 13:13:04"
    }, {
      "id": 5,
      "message": "sup",
      "company_id": 7,
      "investor_id": 35,
      "match_id": 2,
      "created_at": "2015-07-01 15:06:39",
      "updated_at": "2015-07-01 15:06:39"
    }, {
      "id": 1,
      "message": "yo yo ",
      "investor_id": 35,
      "company_id": 7,
      "match_id": 2,
      "created_at": "2015-07-01 22:09:36",
      "updated_at": "-0001-11-30 00:00:00"
    }, {
      "id": 2,
      "message": "sup nigga",
      "investor_id": 35,
      "company_id": 7,
      "match_id": 2,
      "created_at": "2015-07-01 14:00:00",
      "updated_at": "-0001-11-30 00:00:00"
    }]
  </code></pre>
  
  <p>Can anyone teach me how do i have tried many solutions in stackoverflow . Many of them says array cannot be used with "sortBy" .</p>
  
  <p>This is part of my code : </p>
  
  <pre><code>$companyMessage = Company_Message::where('match_id','=',$match_id);
      $investorMessage = Investor_Message::where('match_id','=',$match_id);
      $message = array();
      if($companyMessage-&gt;count()&gt;0 || $investorMessage-&gt;count() &gt; 0){
          if($lastActivityDate == null ){
              //load all messages before 
              if($companyMessage !=null){
                  foreach ($companyMessage-&gt;get() as $cm) {
                      array_push($message,$cm);
                  }
              }
  
              if($investorMessage !=null){
                  foreach($investorMessage-&gt;get() as $im){
                      array_push($message,$im);
                  }
              }
  
              return $message ;   
  
          }
  </code></pre>