mercredi 18 mai 2016

What is Laravel's toBase() doing to this Collection?

    $exclusions = $product->exclusions->lists('excluded_territory');
    $exclusions2 = $product->exclusions->lists('excluded_territory')->toBase();
    dd($exclusions, $exclusions2, $exclusions2->contains('EU'));

Results in:

 Collection {#499 ▼
   #items: array:2 [▼
     0 => "EU"
     1 => "GB"
  ]
 }

 Collection {#458 ▼
   #items: array:2 [▼
     0 => "EU"
     1 => "GB"
  ]
 }

 true

However, if I try to get $exclusions->contains('EU'), I get:

Fatal error: Call to a member function getKey() on string

It's not immediately obvious to me what the difference is between these two Collections, and why I have to run the mysterious toBase() before I can use contains. One is an Eloquent Collection and one is a Support Collection I guess; if that's correct, what's the difference between the two?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/250adNB
via IFTTT

Aucun commentaire:

Enregistrer un commentaire