Last active
August 29, 2015 14:28
-
-
Save lucadegasperi/ff1f2b4d35fcca3f9325 to your computer and use it in GitHub Desktop.
Meta collection in laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MetaCollection extends Collection | |
{ | |
public function __get($name) | |
{ | |
return $this->getValue($name); | |
} | |
public function getValue($name, $default = null) | |
{ | |
$m = $this->filter(function ($meta) use ($name) { | |
return $meta->key == $name; | |
}); | |
if($m->count() > 0) { | |
return $m->first()->value; | |
} | |
return $default; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment