mercredi 16 décembre 2015

Laravel 5 - looping over a Collection

can't seem to figure this out. I have the following code

dd($this->project->dsReportingDoc->reportingDocUpload);
if(!empty($this->project->dsReportingDoc->reportingDocUpload)) {
    dd("TEST");
    foreach($this->project->dsReportingDoc->reportingDocUpload as $key){

    }
}

Now the first dd prints out something like the following

Collection {#274 ▼
  #items: array:2 [▼
    0 => ReportingDocUpload {#275 ▶}
    1 => ReportingDocUpload {#276 ▶}
  ]
}

So, there are two items in the Collection. However, the second dd never seems to get executed, so it must never make it into the if statement.

If anything is in the collection, I need to loop them and get a parameter. So I need to see if the item exists first.

Why would my if statement be failing here when it is not empty?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire