Skip to content

Instantly share code, notes, and snippets.

@lucadegasperi
Last active August 29, 2015 14:28
Show Gist options
  • Save lucadegasperi/ff1f2b4d35fcca3f9325 to your computer and use it in GitHub Desktop.
Save lucadegasperi/ff1f2b4d35fcca3f9325 to your computer and use it in GitHub Desktop.
Meta collection in laravel
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