Skip to content

Instantly share code, notes, and snippets.

@dennisoderwald
Created August 15, 2014 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennisoderwald/a100edcb0fab6981a230 to your computer and use it in GitHub Desktop.
Save dennisoderwald/a100edcb0fab6981a230 to your computer and use it in GitHub Desktop.
morphMany Issue (Now I receive a JSON output with the filtered object, when I call: $model->metas->meta_key)
<?php
class Meta extends Eloquent {
public function newCollection(array $models = array())
{
return new MetaCollection($models);
}
}
<?php
use Illuminate\Database\Eloquent\Collection;
class MetaCollection extends Collection {
public function __get($name)
{
$this->temp = $name;
return $this->filter(function (Meta $item) {
return $item->key == $this->temp;
});
}
}
<?php
class Resort extends Eloquent {
public function metas()
{
return $this->morphMany('Meta', 'metable');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment